Closed
Bug 741325
Opened 12 years ago
Closed 12 years ago
Sort the scripts in the menulist by filename
Categories
(DevTools :: Debugger, defect, P2)
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 15
People
(Reporter: vporof, Assigned: vporof)
References
Details
(Whiteboard: [chrome-debug])
Attachments
(2 files, 1 obsolete file)
12.77 KB,
patch
|
rcampbell
:
review+
|
Details | Diff | Splinter Review |
12.77 KB,
patch
|
Details | Diff | Splinter Review |
No description provided.
Assignee | ||
Updated•12 years ago
|
Component: Developer Tools: Inspector → Developer Tools: Debugger
QA Contact: developer.tools.inspector → developer.tools.debugger
Updated•12 years ago
|
Priority: -- → P2
Assignee | ||
Comment 1•12 years ago
|
||
WIP. Works. Needs a test.
Assignee | ||
Updated•12 years ago
|
Attachment #614697 -
Attachment is obsolete: true
Comment 3•12 years ago
|
||
Comment on attachment 614728 [details] [diff] [review] v2 in debugger-view.js: contains: function DVS_contains(aUrl) { + if (this._tmpScripts.some(function(element) { + return element.script.url == aUrl; + })) { + return true; + } I think this would look better with the .some test on a separate line and a variable used for the truth condition. but that's just a nit. Same for containsLabel(). + * Returns the list of labels in the scripts container. + * @return array + */ + get scriptLabels() { + let labels = []; + for (let i = 0, l = this._scripts.itemCount; i < l; i++) { + labels.push(this._scripts.getItemAtIndex(i).label); + } what about: return this._scripts.map(function(script) { return script.label; }); instead? + for (let i = 0, l = this._scripts.itemCount; i < l; i++) { + if (this._scripts.getItemAtIndex(i).label > aLabel) { + this._createScriptElement(aLabel, aScript, i); + return; + } + } mm. insertion sort. IN THE YEAR 2012! I feel like there should be a cleverer way of doing this but y'know, I'm not sure it's worth it. oh what the hell. You could use a forEach loop and callback with this. Essentially the same thing but cuts down a bit on the extra for loop fiddly bits. this._scripts.forEach(function(script, index) { if (script.label > aLabel) { this._createScriptElement(aLabel, aScript, index); return; } }, this); but that won't return early. Let's just use yours! (I so wanted to be clever there) + /** + * Adds all the prepared scripts to the scripts container. + * If a script already exists (was previously added), nothing happens. + */ + commitScripts: function DVS_commitScripts() { + let newScripts = this._tmpScripts; + this._tmpScripts = []; + + if (!newScripts || !newScripts.length) { + return; + } + newScripts.sort(function(a, b) { + return a.label.toLowerCase() > b.label.toLowerCase(); + }); + + for (let i = 0, l = newScripts.length; i < l; i++) { + let item = newScripts[i]; + this._createScriptElement(item.label, item.script, -1, true); + } + }, + what happens if there are already scripts in the menu? Is that possible? If so, it looks like this won't take them into account and they'll be out of order. however, it looks like the only time a new script can be added to a set of existing scripts is if _onNewScript gets fired. in /test/browser_dbg_scripts-sorting.js + urls.sort(function(a, b) { + return Math.random() - 0.5; + }); why are you randomizing these each time? head hurt. r+ with try.
Attachment #614728 -
Flags: review?(rcampbell) → review+
Assignee | ||
Comment 4•12 years ago
|
||
(In reply to Rob Campbell [:rc] (:robcee) from comment #3) > Comment on attachment 614728 [details] [diff] [review] > v2 > > in debugger-view.js: > > contains: function DVS_contains(aUrl) { > + if (this._tmpScripts.some(function(element) { > + return element.script.url == aUrl; > + })) { > + return true; > + } > > I think this would look better with the .some test on a separate line and a > variable used for the truth condition. but that's just a nit. > Ugh.. > Same for containsLabel(). > > + * Returns the list of labels in the scripts container. > + * @return array > + */ > + get scriptLabels() { > + let labels = []; > + for (let i = 0, l = this._scripts.itemCount; i < l; i++) { > + labels.push(this._scripts.getItemAtIndex(i).label); > + } > > what about: > > return this._scripts.map(function(script) { > return script.label; > }); > > instead? > I was trying to be polite and match the scriptLocations function which looks and feels the same way. But OK! (yay) > + for (let i = 0, l = this._scripts.itemCount; i < l; i++) { > + if (this._scripts.getItemAtIndex(i).label > aLabel) { > + this._createScriptElement(aLabel, aScript, i); > + return; > + } > + } > > mm. insertion sort. IN THE YEAR 2012! Insertion sort IN SOME EDGE CASES! ;) Most of the time addScript will be called with aForceFlag as false, so we lazily sort and add everything. The other case with aForceFlag to true is for the unsolicited newScript notification. We gotta' do insertion sort here if we don't want to clear and re-add everything. > > I feel like there should be a cleverer way of doing this but y'know, I'm not > sure it's worth it. > I wish there was. > oh what the hell. > > You could use a forEach loop and callback with this. Essentially the same > thing but cuts down a bit on the extra for loop fiddly bits. > Gotta' love those functional sugar coatings, but I'm afraid of the cost. Probably won't cost much though. I'll give it a shot and see what happens with 100+ scripts. > this._scripts.forEach(function(script, index) { > if (script.label > aLabel) { > this._createScriptElement(aLabel, aScript, index); > return; > } > }, this); > > but that won't return early. > > Let's just use yours! > > (I so wanted to be clever there) > I feel you. > + /** > + * Adds all the prepared scripts to the scripts container. > + * If a script already exists (was previously added), nothing happens. > + */ > + commitScripts: function DVS_commitScripts() { > + let newScripts = this._tmpScripts; > + this._tmpScripts = []; > + > + if (!newScripts || !newScripts.length) { > + return; > + } > + newScripts.sort(function(a, b) { > + return a.label.toLowerCase() > b.label.toLowerCase(); > + }); > + > + for (let i = 0, l = newScripts.length; i < l; i++) { > + let item = newScripts[i]; > + this._createScriptElement(item.label, item.script, -1, true); > + } > + }, > + > > what happens if there are already scripts in the menu? Is that possible? If > so, it looks like this won't take them into account and they'll be out of > order. > Won't happen. > however, it looks like the only time a new script can be added to a set of > existing scripts is if _onNewScript gets fired. > Exactly. > in /test/browser_dbg_scripts-sorting.js > > + urls.sort(function(a, b) { > + return Math.random() - 0.5; > + }); > > why are you randomizing these each time? > Because WE CAN! But seriously, I don't have a good reason. To make the test misbehave in ways I can't predict and still get green? > head hurt. r+ with try. Thank you!
Assignee | ||
Comment 5•12 years ago
|
||
(In reply to Victor Porof from comment #4) > (In reply to Rob Campbell [:rc] (:robcee) from comment #3) > > > Same for containsLabel(). > > > > + * Returns the list of labels in the scripts container. > > + * @return array > > + */ > > + get scriptLabels() { > > + let labels = []; > > + for (let i = 0, l = this._scripts.itemCount; i < l; i++) { > > + labels.push(this._scripts.getItemAtIndex(i).label); > > + } > > > > what about: > > > > return this._scripts.map(function(script) { > > return script.label; > > }); > > > > instead? > > > > I was trying to be polite and match the scriptLocations function which looks > and feels the same way. But OK! (yay) > Um, wait no, that's not an array. It's a menulist.
Assignee | ||
Comment 6•12 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&rev=0d9b08c361de
Assignee | ||
Comment 7•12 years ago
|
||
Making sure this is the latest patch.
Assignee | ||
Updated•12 years ago
|
Attachment #615798 -
Attachment is patch: true
Assignee | ||
Updated•12 years ago
|
Whiteboard: [chrome-debug] → [chrome-debug][land-in-fx-team]
Comment 8•12 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/3bdab8c31492
Whiteboard: [chrome-debug][land-in-fx-team] → [chrome-debug][fixed-in-fx-team]
Comment 9•12 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/f849003d9864
Whiteboard: [chrome-debug][fixed-in-fx-team] → [chrome-debug][backed-out]
Comment 10•12 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/9285d5ff5ff0
Whiteboard: [chrome-debug][backed-out] → [chrome-debug][fixed-in-fx-team]
Comment 11•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/9285d5ff5ff0
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [chrome-debug][fixed-in-fx-team] → [chrome-debug]
Target Milestone: --- → Firefox 15
Comment 12•12 years ago
|
||
This patch was in a range which caused a Ts regression, so I backed out the whole range: https://hg.mozilla.org/mozilla-central/rev/24a6a53c714a Please reland after investigating and fixing the regression.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment 13•12 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/6fa091e059cc
Whiteboard: [chrome-debug] → [chrome-debug][fixed-in-fx-team]
Comment 14•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/6fa091e059cc
Status: REOPENED → RESOLVED
Closed: 12 years ago → 12 years ago
Resolution: --- → FIXED
Whiteboard: [chrome-debug][fixed-in-fx-team] → [chrome-debug]
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•