|
56 | 56 | * |
57 | 57 | * Pane Object Events: |
58 | 58 | * |
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. |
61 | 61 | * |
62 | 62 | * - currentViewChange - Whenever the current view changes. |
63 | 63 | * (e, newView:View, oldView:View) |
@@ -246,16 +246,33 @@ define(function (require, exports, module) { |
246 | 246 | var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE; |
247 | 247 | var otherPane = MainViewManager._getPane(otherPaneId); |
248 | 248 |
|
| 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 | + |
249 | 260 | MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () { |
250 | 261 | CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath, |
251 | 262 | paneId: otherPaneId}).always(function () { |
252 | | - otherPane.trigger("viewListChange"); |
| 263 | + |
| 264 | + var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip); |
| 265 | + |
| 266 | + // Trigger view list changes for both panes |
253 | 267 | self.trigger("viewListChange"); |
| 268 | + otherPane.trigger("viewListChange"); |
254 | 269 |
|
255 | 270 | // Defer the focusing until other focus events have occurred. |
256 | 271 | 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); |
259 | 276 | }, 1); |
260 | 277 | }); |
261 | 278 | }); |
@@ -564,23 +581,34 @@ define(function (require, exports, module) { |
564 | 581 | // move the item in the working set and |
565 | 582 | // open it in the destination pane |
566 | 583 | 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 | + |
567 | 597 | // Remove file from all 3 view lists |
568 | | - self._viewList.splice(self.findInViewList(file.fullPath), 1); |
| 598 | + self._viewList.splice(viewListIndex, 1); |
569 | 599 | self._viewListMRUOrder.splice(self.findInViewListMRUOrder(file.fullPath), 1); |
570 | 600 | self._viewListAddedOrder.splice(self.findInViewListAddedOrder(file.fullPath), 1); |
571 | 601 |
|
572 | 602 | // insert the view into the working set |
573 | 603 | destinationPane._addToViewList(file, _makeIndexRequestObject(true, destinationIndex)); |
574 | 604 |
|
575 | | - //move the view, |
576 | | - var view = self._views[file.fullPath]; |
577 | | - |
578 | 605 | // 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 |
580 | 607 | if (view) { |
581 | 608 | // delete it from the source pane's view map and add it to the destination pane's view map |
582 | 609 | delete self._views[file.fullPath]; |
583 | 610 | destinationPane.addView(view, !destinationPane.getCurrentlyViewedFile()); |
| 611 | + |
584 | 612 | // we're done |
585 | 613 | result.resolve(); |
586 | 614 | } else if (!destinationPane.getCurrentlyViewedFile()) { |
@@ -819,7 +847,6 @@ define(function (require, exports, module) { |
819 | 847 | */ |
820 | 848 | Pane.prototype.addToViewList = function (file, index) { |
821 | 849 | var indexRequested = (index !== undefined && index !== null && index >= 0 && index < this._viewList.length); |
822 | | - |
823 | 850 | this._addToViewList(file, _makeIndexRequestObject(indexRequested, index)); |
824 | 851 |
|
825 | 852 | if (!indexRequested) { |
|
0 commit comments