Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 830c83c

Browse files
committed
Merge pull request #4450 from TomMalbran/tom/issue-2076-take2
Better fix for #2076: Two indistinguishable events for different cases of working set reordering. Now listening for a single event is enough to track all working set reordering.
2 parents 0e61321 + 6ba1525 commit 830c83c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/document/DocumentManager.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ define(function (require, exports, module) {
367367

368368
/**
369369
* Mutually exchanges the files at the indexes passed by parameters.
370-
* @param {!number} index - old file index
371-
* @param {!number} index - new file index
370+
* @param {number} index Old file index
371+
* @param {number} index New file index
372372
*/
373373
function swapWorkingSetIndexes(index1, index2) {
374374
var length = _workingSet.length - 1;
@@ -378,13 +378,15 @@ define(function (require, exports, module) {
378378
temp = _workingSet[index1];
379379
_workingSet[index1] = _workingSet[index2];
380380
_workingSet[index2] = temp;
381+
382+
$(exports).triggerHandler("workingSetSort");
381383
$(exports).triggerHandler("workingSetDisableAutoSorting");
382384
}
383385
}
384386

385387
/**
386388
* Sorts _workingSet using the compare function
387-
* @param {!function(FileEntry, FileEntry)} compareFn - the function that will be used inside JavaScript's
389+
* @param {function(FileEntry, FileEntry): number} compareFn The function that will be used inside JavaScript's
388390
* sort function. The return a value should be >0 (sort a to a lower index than b), =0 (leaves a and b
389391
* unchanged with respect to each other) or <0 (sort b to a lower index than a) and must always returns
390392
* the same value when given a specific pair of elements a and b as its two arguments.
@@ -422,7 +424,7 @@ define(function (require, exports, module) {
422424
/**
423425
* Get the next or previous file in the working set, in MRU order (relative to currentDocument). May
424426
* return currentDocument itself if working set is length 1.
425-
* @param {Number} inc -1 for previous, +1 for next; no other values allowed
427+
* @param {number} inc -1 for previous, +1 for next; no other values allowed
426428
* @return {?FileEntry} null if working set empty
427429
*/
428430
function getNextPrevFile(inc) {

src/project/WorkingSetView.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ define(function (require, exports, module) {
5050
$openFilesContainer,
5151
$openFilesList;
5252

53+
/**
54+
* @private
55+
* Internal flag to suppress redrawing the Working Set after a workingSetSort event.
56+
* @type {boolean}
57+
*/
58+
var _suppressSortRedraw = false;
59+
60+
5361
/**
5462
* @private
5563
* Redraw selection when list size changes or DocumentManager currentDocument changes.
@@ -179,6 +187,9 @@ define(function (require, exports, module) {
179187
if (!moved && Math.abs(top) > 3) {
180188
Menus.closeAll();
181189
moved = true;
190+
191+
// Don't redraw the working set for the next events
192+
_suppressSortRedraw = true;
182193
}
183194
}
184195

@@ -256,6 +267,9 @@ define(function (require, exports, module) {
256267
if (addBottomShadow) {
257268
ViewUtils.addScrollerShadow($openFilesContainer[0], null, true);
258269
}
270+
271+
// The drag is done, so set back to the default
272+
_suppressSortRedraw = false;
259273
}
260274
}
261275

@@ -550,11 +564,13 @@ define(function (require, exports, module) {
550564
_redraw();
551565
}
552566

553-
/**
567+
/**
554568
* @private
555569
*/
556570
function _handleWorkingSetSort() {
557-
_rebuildWorkingSet(true);
571+
if (!_suppressSortRedraw) {
572+
_rebuildWorkingSet(true);
573+
}
558574
}
559575

560576
/**

0 commit comments

Comments
 (0)