Skip to content

Commit

Permalink
Prevent same doc flip to avoid document corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
swmitra committed Jan 11, 2016
1 parent 0a4823a commit 2c058f1
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/view/Pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,29 @@ define(function (require, exports, module) {
if (currentFileOnOtherPaneIndex !== -1) {
CommandManager.execute(Commands.FILE_CLOSE, {File: currentFile, paneId: self.id});
}

MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () {
CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath,
paneId: otherPaneId}).always(function () {

var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip);

// Trigger view list changes for both panes
self.trigger("viewListChange");
otherPane.trigger("viewListChange");

// Defer the focusing until other focus events have occurred.
setTimeout(function () {
// Focus has most likely changed: give it back to the original pane.
activePaneBeforeFlip.focus();
self._lastFocusedElement = activePaneBeforeFlip.$el[0];
MainViewManager.setActivePaneId(activePaneIdBeforeFlip);
}, 1);

// If the same doc view is present in the destination pane prevent flip
if (!otherPane.getViewForPath(currentFile.fullPath)) {
MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () {
CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath,
paneId: otherPaneId}).always(function () {

var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip);

// Trigger view list changes for both panes
self.trigger("viewListChange");
otherPane.trigger("viewListChange");

// Defer the focusing until other focus events have occurred.
setTimeout(function () {
// Focus has most likely changed: give it back to the original pane.
activePaneBeforeFlip.focus();
self._lastFocusedElement = activePaneBeforeFlip.$el[0];
MainViewManager.setActivePaneId(activePaneIdBeforeFlip);
}, 1);
});
});
});
}
});

// Closes the current view on the pane when clicked. If pane has no files, merge
Expand Down

0 comments on commit 2c058f1

Please sign in to comment.