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

Commit

Permalink
Fix for external change handling (#13545)
Browse files Browse the repository at this point in the history
  • Loading branch information
swmitra authored and saurabh95 committed Aug 3, 2017
1 parent ea26171 commit 7211d7f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/extensions/default/NavigationAndHistory/NavigationProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ define(function (require, exports, module) {
fileEntry.exists(function (err, exists) {
if (!err && exists) {
// Additional check to handle external modification and mutation of the doc text affecting markers
if (fileEntry._stat !== entry.fileStat) {
if (fileEntry._hash !== entry._hash) {
deferred.reject();
} else if (!entry._validateMarkers()) {
deferred.reject();
Expand All @@ -135,7 +135,7 @@ define(function (require, exports, module) {
this.filePath = editor.document.file._path;
this.inMem = editor.document.file.constructor.name === "InMemoryFile";
this.paneId = editor._paneId;
this.fileStat = editor.document.file._stat;
this._hash = editor.document.file._hash;
this.uId = (new Date()).getTime();
this.selections = [];
this.bookMarkIds = [];
Expand Down Expand Up @@ -166,6 +166,15 @@ define(function (require, exports, module) {
this._createMarkers(this.selections);
};


/**
* Function to validate an existing frame against a file '_hash' to detect
* external change so that the frame can be discarded
*/
NavigationFrame.prototype._validateFileHash = function (file) {
return this.filePath === file._path ? this._hash === file._hash : true;
};

/**
* Function to create CM TextMarkers for the navigated positions/selections.
* This logic is required to ensure that the captured navigation positions
Expand Down Expand Up @@ -461,7 +470,7 @@ define(function (require, exports, module) {
*/
function _removeBackwardFramesForFile(file) {
jumpBackwardStack = jumpBackwardStack.filter(function (frame) {
return frame.filePath !== file._path && frame.stat !== file._stat;
return frame._validateFileHash(file);
});
}

Expand All @@ -471,7 +480,7 @@ define(function (require, exports, module) {
*/
function _removeForwardFramesForFile(file) {
jumpForwardStack = jumpForwardStack.filter(function (frame) {
return frame.filePath !== file._path && frame.stat !== file._stat;
return frame._validateFileHash(file);
});
}

Expand Down

0 comments on commit 7211d7f

Please sign in to comment.