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

Commit

Permalink
Handle InMemory files in recent file list (#12496)
Browse files Browse the repository at this point in the history
* Handle InMemory files in recent file list

* Updating tab spacing

* Update main.js

* Update main.js

* Fix tab spacing issues
  • Loading branch information
swmitra authored and nethip committed Jun 8, 2016
1 parent 60bcc7b commit b0a363b
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/extensions/default/NavigationAndHistory/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -755,7 +774,7 @@ define(function (require, exports, module) {
_initRecentFilesList();
}

_addToMROFList(newFile.fullPath, newPaneId);
_addToMROFList(newFile, newPaneId);
}
}

Expand All @@ -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
Expand Down

0 comments on commit b0a363b

Please sign in to comment.