|
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)
|
@@ -245,12 +245,40 @@ define(function (require, exports, module) {
|
245 | 245 | var currentFile = self.getCurrentlyViewedFile();
|
246 | 246 | var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE;
|
247 | 247 | var otherPane = MainViewManager._getPane(otherPaneId);
|
| 248 | + |
| 249 | + // If the same doc view is present in the destination pane prevent flip |
| 250 | + if (otherPane.getViewForPath(currentFile.fullPath)) { |
| 251 | + return; |
| 252 | + } |
| 253 | + |
| 254 | + // Currently active pane is not necessarily self.id as just clicking the button does not |
| 255 | + // give focus to the pane. This way it is possible to flip multiple panes to the active one |
| 256 | + // without losing focus. |
| 257 | + var activePaneIdBeforeFlip = MainViewManager.getActivePaneId(); |
| 258 | + var currentFileOnOtherPaneIndex = otherPane.findInViewList(currentFile.fullPath); |
248 | 259 |
|
| 260 | + // if the currentFile is already on other pane just close the current pane |
| 261 | + if (currentFileOnOtherPaneIndex !== -1) { |
| 262 | + CommandManager.execute(Commands.FILE_CLOSE, {File: currentFile, paneId: self.id}); |
| 263 | + } |
| 264 | + |
249 | 265 | MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () {
|
250 | 266 | CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath,
|
251 | 267 | paneId: otherPaneId}).always(function () {
|
252 |
| - otherPane.trigger("viewListChange"); |
| 268 | + |
| 269 | + var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip); |
| 270 | + |
| 271 | + // Trigger view list changes for both panes |
253 | 272 | self.trigger("viewListChange");
|
| 273 | + otherPane.trigger("viewListChange"); |
| 274 | + |
| 275 | + // Defer the focusing until other focus events have occurred. |
| 276 | + setTimeout(function () { |
| 277 | + // Focus has most likely changed: give it back to the original pane. |
| 278 | + activePaneBeforeFlip.focus(); |
| 279 | + self._lastFocusedElement = activePaneBeforeFlip.$el[0]; |
| 280 | + MainViewManager.setActivePaneId(activePaneIdBeforeFlip); |
| 281 | + }, 1); |
254 | 282 | });
|
255 | 283 | });
|
256 | 284 | });
|
@@ -558,23 +586,34 @@ define(function (require, exports, module) {
|
558 | 586 | // move the item in the working set and
|
559 | 587 | // open it in the destination pane
|
560 | 588 | openNextPromise.done(function () {
|
| 589 | + var viewListIndex = self.findInViewList(file.fullPath); |
| 590 | + var shouldAddView = viewListIndex !== -1; |
| 591 | + var view = self._views[file.fullPath]; |
| 592 | + |
| 593 | + // If the file isn't in working set, destroy the view and delete it from |
| 594 | + // source pane's view map and return as solved |
| 595 | + if (!shouldAddView) { |
| 596 | + if (view) { |
| 597 | + self._doDestroyView(view); |
| 598 | + } |
| 599 | + return result.resolve(); |
| 600 | + } |
| 601 | + |
561 | 602 | // Remove file from all 3 view lists
|
562 |
| - self._viewList.splice(self.findInViewList(file.fullPath), 1); |
| 603 | + self._viewList.splice(viewListIndex, 1); |
563 | 604 | self._viewListMRUOrder.splice(self.findInViewListMRUOrder(file.fullPath), 1);
|
564 | 605 | self._viewListAddedOrder.splice(self.findInViewListAddedOrder(file.fullPath), 1);
|
565 | 606 |
|
566 | 607 | // insert the view into the working set
|
567 | 608 | destinationPane._addToViewList(file, _makeIndexRequestObject(true, destinationIndex));
|
568 | 609 |
|
569 |
| - //move the view, |
570 |
| - var view = self._views[file.fullPath]; |
571 |
| - |
572 | 610 | // if we had a view, it had previously been opened
|
573 |
| - // otherwise, the file was in the working set unopened |
| 611 | + // otherwise, the file was in the working set unopened |
574 | 612 | if (view) {
|
575 | 613 | // delete it from the source pane's view map and add it to the destination pane's view map
|
576 | 614 | delete self._views[file.fullPath];
|
577 | 615 | destinationPane.addView(view, !destinationPane.getCurrentlyViewedFile());
|
| 616 | + |
578 | 617 | // we're done
|
579 | 618 | result.resolve();
|
580 | 619 | } else if (!destinationPane.getCurrentlyViewedFile()) {
|
@@ -813,7 +852,6 @@ define(function (require, exports, module) {
|
813 | 852 | */
|
814 | 853 | Pane.prototype.addToViewList = function (file, index) {
|
815 | 854 | var indexRequested = (index !== undefined && index !== null && index >= 0 && index < this._viewList.length);
|
816 |
| - |
817 | 855 | this._addToViewList(file, _makeIndexRequestObject(indexRequested, index));
|
818 | 856 |
|
819 | 857 | if (!indexRequested) {
|
|
0 commit comments