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

Commit ddcbcca

Browse files
committed
Fix FlipView / WorkingSet / SplitViewSameDoc integration issues
1 parent c92e4df commit ddcbcca

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/view/Pane.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
*
5757
* Pane Object Events:
5858
*
59-
* - viewListChange - Whenever there is a file change to a file in the working set. These 2 events: `DocumentManger.pathRemove`
60-
* and `DocumentManger.fileNameChange` will cause a `viewListChange` event so the WorkingSetView can update.
59+
* - viewListChange - Whenever there is a file change to a file in the working set. These 2 events: `DocumentManager.pathRemove`
60+
* and `DocumentManager.fileNameChange` will cause a `viewListChange` event so the WorkingSetView can update.
6161
*
6262
* - currentViewChange - Whenever the current view changes.
6363
* (e, newView:View, oldView:View)
@@ -246,16 +246,33 @@ define(function (require, exports, module) {
246246
var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE;
247247
var otherPane = MainViewManager._getPane(otherPaneId);
248248

249+
// Currently active pane is not necessarily self.id as just clicking the button does not
250+
// give focus to the pane. This way it is possible to flip multiple panes to the active one
251+
// without losing focus.
252+
var activePaneIdBeforeFlip = MainViewManager.getActivePaneId();
253+
var currentFileOnOtherPaneIndex = otherPane.findInViewList(currentFile.fullPath);
254+
255+
// if the currentFile is already on other pane just close the current pane
256+
if (currentFileOnOtherPaneIndex !== -1) {
257+
CommandManager.execute(Commands.FILE_CLOSE, {File: currentFile, paneId: self.id});
258+
}
259+
249260
MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () {
250261
CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath,
251262
paneId: otherPaneId}).always(function () {
252-
otherPane.trigger("viewListChange");
263+
264+
var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip);
265+
266+
// Trigger view list changes for both panes
253267
self.trigger("viewListChange");
268+
otherPane.trigger("viewListChange");
254269

255270
// Defer the focusing until other focus events have occurred.
256271
setTimeout(function () {
257-
MainViewManager.setActivePaneId(otherPaneId);
258-
self._lastFocusedElement = otherPane.$el[0];
272+
// Focus has most likely changed: give it back to the original pane.
273+
activePaneBeforeFlip.focus();
274+
self._lastFocusedElement = activePaneBeforeFlip.$el[0];
275+
MainViewManager.setActivePaneId(activePaneIdBeforeFlip);
259276
}, 1);
260277
});
261278
});
@@ -564,23 +581,34 @@ define(function (require, exports, module) {
564581
// move the item in the working set and
565582
// open it in the destination pane
566583
openNextPromise.done(function () {
584+
var viewListIndex = self.findInViewList(file.fullPath);
585+
var shouldAddView = viewListIndex !== -1;
586+
var view = self._views[file.fullPath];
587+
588+
// If the file isn't in working set, destroy the view and delete it from
589+
// source pane's view map and return as solved
590+
if (!shouldAddView) {
591+
if (view) {
592+
self._doDestroyView(view);
593+
}
594+
return result.resolve();
595+
}
596+
567597
// Remove file from all 3 view lists
568-
self._viewList.splice(self.findInViewList(file.fullPath), 1);
598+
self._viewList.splice(viewListIndex, 1);
569599
self._viewListMRUOrder.splice(self.findInViewListMRUOrder(file.fullPath), 1);
570600
self._viewListAddedOrder.splice(self.findInViewListAddedOrder(file.fullPath), 1);
571601

572602
// insert the view into the working set
573603
destinationPane._addToViewList(file, _makeIndexRequestObject(true, destinationIndex));
574604

575-
//move the view,
576-
var view = self._views[file.fullPath];
577-
578605
// if we had a view, it had previously been opened
579-
// otherwise, the file was in the working set unopened
606+
// otherwise, the file was in the working set unopened
580607
if (view) {
581608
// delete it from the source pane's view map and add it to the destination pane's view map
582609
delete self._views[file.fullPath];
583610
destinationPane.addView(view, !destinationPane.getCurrentlyViewedFile());
611+
584612
// we're done
585613
result.resolve();
586614
} else if (!destinationPane.getCurrentlyViewedFile()) {
@@ -819,7 +847,6 @@ define(function (require, exports, module) {
819847
*/
820848
Pane.prototype.addToViewList = function (file, index) {
821849
var indexRequested = (index !== undefined && index !== null && index >= 0 && index < this._viewList.length);
822-
823850
this._addToViewList(file, _makeIndexRequestObject(indexRequested, index));
824851

825852
if (!indexRequested) {

0 commit comments

Comments
 (0)