From b0a363b71822e16936f5cac4ddc93066e620853f Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Wed, 8 Jun 2016 12:04:09 +0530 Subject: [PATCH] Handle InMemory files in recent file list (#12496) * Handle InMemory files in recent file list * Updating tab spacing * Update main.js * Update main.js * Fix tab spacing issues --- .../default/NavigationAndHistory/main.js | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/extensions/default/NavigationAndHistory/main.js b/src/extensions/default/NavigationAndHistory/main.js index e49d1c0fd73..356fe4d4a20 100644 --- a/src/extensions/default/NavigationAndHistory/main.js +++ b/src/extensions/default/NavigationAndHistory/main.js @@ -164,14 +164,25 @@ define(function (require, exports, module) { var deferred = new $.Deferred(), fileEntry = FileSystem.getFileForPath(entry.file); - fileEntry.exists(function (err, exists) { - if (!err && exists) { - deferred.resolve(); - } else { + if (entry.inMem) { + var indxInWS = MainViewManager.findInWorkingSet(entry.paneId, entry.file); + // Remove entry if InMemoryFile is not found in Working set + if (indxInWS === -1) { _mrofList[index] = null; deferred.reject(); + } else { + deferred.resolve(); } - }); + } else { + fileEntry.exists(function (err, exists) { + if (!err && exists) { + deferred.resolve(); + } else { + _mrofList[index] = null; + deferred.reject(); + } + }); + } return deferred.promise(); } @@ -569,7 +580,9 @@ define(function (require, exports, module) { * @private * @param {Editor} editor - editor to extract file information */ - function _addToMROFList(filePath, paneId, cursorPos) { + function _addToMROFList(file, paneId, cursorPos) { + + var filePath = file.fullPath; if (!paneId) { // Don't handle this if not a full view/editor return; @@ -591,6 +604,13 @@ define(function (require, exports, module) { entry = _makeMROFListEntry(filePath, paneId, cursorPos); + // Check if the file is an InMemoryFile + if (file.constructor.name === "InMemoryFile") { + // Mark the entry as inMem, so that we can knock it off from the list when removed from working set + entry.inMem = true; + } + + if (index !== -1) { _mrofList.splice(index, 1); } @@ -600,7 +620,6 @@ define(function (require, exports, module) { PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true); } - // To update existing entry if a move has happened function _handleWorkingSetMove(event, file, sourcePaneId, destinationPaneId) { @@ -755,7 +774,7 @@ define(function (require, exports, module) { _initRecentFilesList(); } - _addToMROFList(newFile.fullPath, newPaneId); + _addToMROFList(newFile, newPaneId); } } @@ -766,9 +785,9 @@ define(function (require, exports, module) { _initRecentFilesList(); } - var filePath = current.document.file.fullPath; + var file = current.document.file; var paneId = current._paneId; - _addToMROFList(filePath, paneId, current.getCursorPos(true, "first")); + _addToMROFList(file, paneId, current.getCursorPos(true, "first")); } if (previous) { // Capture the last know cursor position