From 55ae8a597e5fa8d646dbf4b42cec838c9286d15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 15 Nov 2012 05:26:40 -0300 Subject: [PATCH 1/4] When closing a file, next in wsMRU will open --- src/document/DocumentManager.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index d832b583d56..446544167ae 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -454,22 +454,20 @@ define(function (require, exports, module) { // If this was the current document shown in the editor UI, we're going to switch to a // different document (or none if working set has no other options) if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { - var wsIndex = findInWorkingSet(file.fullPath); + var wsIndex = findInWorkingSet(file.fullPath, _workingSetMRUOrder); // Decide which doc to show in editor after this one var nextFile; if (wsIndex === -1) { - // If doc wasn't in working set, use bottommost working set item - if (_workingSet.length > 0) { - nextFile = _workingSet[_workingSet.length - 1]; + // If doc wasn't in working set, use last visited file, first item in workingSetMRUOrder + if (_workingSetMRUOrder.length > 0) { + nextFile = _workingSetMRUOrder[0]; } // else: leave nextDocument null; editor area will be blank } else { - // If doc was in working set, use item next to it (below if possible) - if (wsIndex < _workingSet.length - 1) { - nextFile = _workingSet[wsIndex + 1]; - } else if (wsIndex > 0) { - nextFile = _workingSet[wsIndex - 1]; + // If doc was in working set, go to the previously visited file (if there is another file opened) + if (wsIndex < _workingSetMRUOrder.length - 1) { + nextFile = _workingSetMRUOrder[wsIndex + 1]; } // else: leave nextDocument null; editor area will be blank } From 1a57ee701ae9c51840e83f7a0d841370b3e597d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 6 Dec 2012 03:02:46 -0300 Subject: [PATCH 2/4] Replacing next file logic with getNextPrevFile --- src/document/DocumentManager.js | 87 ++++++++++++++------------------- 1 file changed, 37 insertions(+), 50 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index 0f2ae5acbd1..aa7b5baed55 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -390,6 +390,41 @@ define(function (require, exports, module) { } + /** + * Get the next or previous file in the working set, in MRU order (relative to currentDocument). + * @param {Number} inc -1 for previous, +1 for next; no other values allowed + * @return {?FileEntry} null if working set empty + */ + function getNextPrevFile(inc) { + if (inc !== -1 && inc !== +1) { + throw new Error("Illegal argument: inc = " + inc); + } + + if (_currentDocument) { + var mruI = findInWorkingSet(_currentDocument.file.fullPath, _workingSetMRUOrder); + if (mruI === -1) { + // If doc not in working set, return most recent working set item + if (_workingSetMRUOrder.length > 0) { + return _workingSetMRUOrder[0]; + } + } else { + // If doc is in working set, return next/prev item with wrap-around + var newI = mruI + inc; + if (newI >= _workingSetMRUOrder.length) { + newI = 0; + } else if (newI < 0) { + newI = _workingSetMRUOrder.length - 1; + } + + return _workingSetMRUOrder[newI]; + } + } + + // If no doc open or working set empty, there is no "next" file + return null; + } + + /** * Changes currentDocument to the given Document, firing currentDocumentChange, which in turn * causes this Document's main editor UI to be shown in the editor pane, updates the selection @@ -456,21 +491,8 @@ define(function (require, exports, module) { if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { var wsIndex = findInWorkingSet(file.fullPath, _workingSetMRUOrder); - // Decide which doc to show in editor after this one - var nextFile; - if (wsIndex === -1) { - // If doc wasn't in working set, use last visited file, first item in workingSetMRUOrder - if (_workingSetMRUOrder.length > 0) { - nextFile = _workingSetMRUOrder[0]; - } - // else: leave nextDocument null; editor area will be blank - } else { - // If doc was in working set, go to the previously visited file (if there is another file opened) - if (wsIndex < _workingSetMRUOrder.length - 1) { - nextFile = _workingSetMRUOrder[wsIndex + 1]; - } - // else: leave nextDocument null; editor area will be blank - } + // Decide which doc to show in editor after this one using the MRU order + var nextFile = getNextPrevFile(wsIndex === -1 ? -1 : 1); // Switch editor to next document (or blank it out) if (nextFile) { @@ -1008,41 +1030,6 @@ define(function (require, exports, module) { } - /** - * Get the next or previous file in the working set, in MRU order (relative to currentDocument). - * @param {Number} inc -1 for previous, +1 for next; no other values allowed - * @return {?FileEntry} null if working set empty - */ - function getNextPrevFile(inc) { - if (inc !== -1 && inc !== +1) { - throw new Error("Illegal argument: inc = " + inc); - } - - if (_currentDocument) { - var mruI = findInWorkingSet(_currentDocument.file.fullPath, _workingSetMRUOrder); - if (mruI === -1) { - // If doc not in working set, return most recent working set item - if (_workingSetMRUOrder.length > 0) { - return _workingSetMRUOrder[0]; - } - } else { - // If doc is in working set, return next/prev item with wrap-around - var newI = mruI + inc; - if (newI >= _workingSetMRUOrder.length) { - newI = 0; - } else if (newI < 0) { - newI = _workingSetMRUOrder.length - 1; - } - - return _workingSetMRUOrder[newI]; - } - } - - // If no doc open or working set empty, there is no "next" file - return null; - } - - /** * @private * Preferences callback. Saves the document file paths for the working set. From 496b994a7b4ff6d7971372b82f1c329f8e669530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 6 Dec 2012 03:16:32 -0300 Subject: [PATCH 3/4] Really using it now --- src/document/DocumentManager.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index aa7b5baed55..b2d71a01463 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -489,10 +489,8 @@ define(function (require, exports, module) { // If this was the current document shown in the editor UI, we're going to switch to a // different document (or none if working set has no other options) if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { - var wsIndex = findInWorkingSet(file.fullPath, _workingSetMRUOrder); - - // Decide which doc to show in editor after this one using the MRU order - var nextFile = getNextPrevFile(wsIndex === -1 ? -1 : 1); + // Get the previows doc from the MRU order + var nextFile = getNextPrevFile(-1); // Switch editor to next document (or blank it out) if (nextFile) { From e73c8835345e3f8307d01344ada0211cf63c5cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 6 Dec 2012 17:47:32 -0300 Subject: [PATCH 4/4] Going to the right document this time --- src/document/DocumentManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index b2d71a01463..aa9a9cc7ca5 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -490,7 +490,7 @@ define(function (require, exports, module) { // different document (or none if working set has no other options) if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { // Get the previows doc from the MRU order - var nextFile = getNextPrevFile(-1); + var nextFile = getNextPrevFile(1); // Switch editor to next document (or blank it out) if (nextFile) {