-
Notifications
You must be signed in to change notification settings - Fork 11
Bugfix/template loader naming collision #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YuanQI295
wants to merge
6
commits into
ynput:develop
Choose a base branch
from
YuanQI295:fix/template-loader-naming-collision
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−22
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a756be0
first commit with code
YuanQI295 3430359
first commit
YuanQI295 8de613d
cleaned code
YuanQI295 ebdb134
cleaned code
YuanQI295 3d7b8e0
cleaned code
YuanQI295 5f40b81
remove vendored OpenHarmony from tracking
YuanQI295 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,7 @@ TemplateLoader.prototype.loadContainer = function(args) { | |||||
| var templatePath = args[0]; | ||||||
| var overrideName = args[1] || ""; | ||||||
| var parentBackdropName = args[2] || null; | ||||||
| var existingNames = args[3] || []; | ||||||
|
|
||||||
| // Copy from template file | ||||||
| MessageLog.trace("loadContainer:: "); | ||||||
|
|
@@ -51,7 +52,7 @@ TemplateLoader.prototype.loadContainer = function(args) { | |||||
| function parseBackdropName(name) { | ||||||
| var lastIndex = name.lastIndexOf('_'); | ||||||
| if (lastIndex === -1) { | ||||||
| return { baseName: name, count: 1 }; | ||||||
| return { baseName: name, count: 0 }; | ||||||
| } | ||||||
| var base = name.substring(0, lastIndex); | ||||||
| var suffix = name.substring(lastIndex + 1); | ||||||
|
|
@@ -60,7 +61,7 @@ TemplateLoader.prototype.loadContainer = function(args) { | |||||
| if (isNumericSuffix) { | ||||||
| return { baseName: base, count: increment }; | ||||||
| } | ||||||
| return { baseName: name, count: 1 }; | ||||||
| return { baseName: name, count: 0 }; | ||||||
| } | ||||||
|
|
||||||
| var _copyOptions = copyPaste.getCurrentCreateOptions(); | ||||||
|
|
@@ -134,27 +135,28 @@ TemplateLoader.prototype.loadContainer = function(args) { | |||||
| mainBackdrop.title.text = overrideName; | ||||||
| } | ||||||
|
|
||||||
| // Count existing backdrops by base name | ||||||
| var backdropCounts = {}; | ||||||
| for (var i = 0; i < allBackdrops.length; i++) { | ||||||
| var parsed = parseBackdropName(allBackdrops[i].title.text); | ||||||
| var baseName = parsed.baseName; | ||||||
| var count = parsed.count; | ||||||
|
|
||||||
| if (backdropCounts[baseName]) { | ||||||
| backdropCounts[baseName]++; | ||||||
| } else { | ||||||
| backdropCounts[baseName] = count; | ||||||
| var mainBackdropBaseName = parseBackdropName(mainBackdrop.title.text).baseName; | ||||||
|
|
||||||
| // Collect used suffix slots for this baseName, based on the | ||||||
| // Python-provided list of already-registered container names | ||||||
| var usedNumbers = []; | ||||||
| for (var n = 0; n < existingNames.length; n++) { | ||||||
| var parsed = parseBackdropName(existingNames[n]); | ||||||
| if (parsed.baseName !== mainBackdropBaseName) { | ||||||
| continue; | ||||||
| } | ||||||
| usedNumbers.push(parsed.count); | ||||||
| } | ||||||
|
|
||||||
| // Increment count of backdrop with the same base name | ||||||
| var mainBackdropName = mainBackdrop.title.text; | ||||||
| var mainBackdropParsed = parseBackdropName(mainBackdropName); | ||||||
| var count = backdropCounts[mainBackdropParsed.baseName] !== undefined ? backdropCounts[mainBackdropParsed.baseName] : 1; | ||||||
| if (count > 1){ | ||||||
| // count -1 to match imported nodes which start from _1 | ||||||
| mainBackdropName = mainBackdropName + "_" + (count - 1); | ||||||
| var mainBackdropName; | ||||||
| if (usedNumbers.indexOf(0) === -1) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be faster,
Suggested change
|
||||||
| mainBackdropName = mainBackdropBaseName; | ||||||
| } else { | ||||||
| var nextSuffix = 1; | ||||||
| while (usedNumbers.indexOf(nextSuffix) !== -1) { | ||||||
| nextSuffix++; | ||||||
| } | ||||||
| mainBackdropName = mainBackdropBaseName + "_" + nextSuffix; | ||||||
| } | ||||||
|
|
||||||
| // Set name of main backdrop (always at index 0) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule OpenHarmony
deleted from
763169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange, existing names better be collected on the JS side. Or the whole function should be refactored in order to deal with correct name on the python side and passed as
overrideName.@kalisp do you have a preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we were adding numeric suffixes in JS, weren't we? So probably JS to match.