-
Notifications
You must be signed in to change notification settings - Fork 62
fix duplicate name error warning logic #821
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -771,20 +771,29 @@ $(document).ready(function() { | |
|
|
||
| // Finally, mark duplicate names | ||
| names.sort(Numbas.util.sortBy('name')); | ||
| var groupArray = []; | ||
| function handle_group(group) { | ||
| group.forEach(function(n) { | ||
| n.v.duplicateNameError(group.length > 1 ? n.name : null); | ||
| group.forEach(function (n) { | ||
| n.v.duplicateNameError(null); | ||
|
Member
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. While it won't noticeably affect performance, you can avoid having two nested |
||
| }); | ||
| groupArray.push(group); | ||
| } | ||
|
|
||
| var start = 0; | ||
| names.forEach(function(n,i) { | ||
| if(n.name!=names[start].name) { | ||
| handle_group(names.slice(start,i)); | ||
| names.forEach(function (n, i) { | ||
| if (n.name != names[start].name) { | ||
| handle_group(names.slice(start, i)); | ||
| start = i; | ||
| } | ||
| }); | ||
| handle_group(names.slice(start)); | ||
| // Triggers duplicateNameError observable for groups with duplicates | ||
| groupArray.forEach(function (group) { | ||
| var groupVariable = group[0]; | ||
| if (group.length > 1 && groupVariable.name != "") { | ||
| groupVariable.v.duplicateNameError(groupVariable.name); | ||
|
Member
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. You're only setting Again, |
||
| } | ||
| }) | ||
| },this).extend({rateLimit: 2000}); | ||
|
|
||
| /** Create an instance of this question as a Numbas.Question object. | ||
|
|
@@ -1963,10 +1972,10 @@ $(document).ready(function() { | |
|
|
||
| var nameError = ko.pureComputed(function() { | ||
| var duplicateNameError = v.duplicateNameError(); | ||
| var name_errors = names().map(function(nd) { | ||
| var name_errors = names().map(function (nd) { | ||
| var name = nd.name; | ||
| if(name.toLowerCase() == duplicateNameError) { | ||
| return 'There\'s another variable or constant with the name '+name+'.'; | ||
| if (name.toLowerCase() == duplicateNameError) { | ||
| return 'There\'s another variable or constant with the name ' + name + '.'; | ||
| } | ||
| if(name=='') { | ||
| return ''; | ||
|
|
||
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 don't think it's a good idea to include the type of a variable in its name. This could just be called
groups.