From c7e80a5a92a95a210ed7c9b6824a4ada6850a135 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Thu, 24 Dec 2015 15:48:13 +0530 Subject: [PATCH 01/10] Fix for non working Ctrl+Click and Ctrl+Shift+Click for opening same document on targeted panes --- src/document/DocumentCommandHandlers.js | 2 +- src/project/FileTreeView.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 2af75899659..0cf958a1dec 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -291,7 +291,7 @@ define(function (require, exports, module) { // TODO should be removed once bug is closed. // if we are already displaying a file do nothing but resolve immediately. // this fixes timing issues in test cases. - if (MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE) === fullPath) { + if (MainViewManager.getCurrentlyViewedPath(paneId || MainViewManager.ACTIVE_PANE) === fullPath) { result.resolve(MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE)); return result.promise(); } diff --git a/src/project/FileTreeView.js b/src/project/FileTreeView.js index 3b12972a841..cd1f78273d6 100644 --- a/src/project/FileTreeView.js +++ b/src/project/FileTreeView.js @@ -398,7 +398,7 @@ define(function (require, exports, module) { return; } - if (this.props.entry.get("selected")) { + if (this.props.entry.get("selected") && !e.ctrlKey) { if (this.state.clickTimer === null && !this.props.entry.get("rename")) { var timer = window.setTimeout(this.startRename, CLICK_RENAME_MINIMUM); this.setState({ From 8808b4e36a47987f7e4d20350eb7febb8b81c614 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Wed, 6 Jan 2016 13:59:12 +0530 Subject: [PATCH 02/10] Null doc fix --- src/document/DocumentCommandHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 0cf958a1dec..cf11bc0cd15 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -292,7 +292,7 @@ define(function (require, exports, module) { // if we are already displaying a file do nothing but resolve immediately. // this fixes timing issues in test cases. if (MainViewManager.getCurrentlyViewedPath(paneId || MainViewManager.ACTIVE_PANE) === fullPath) { - result.resolve(MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE)); + result.resolve(MainViewManager.getCurrentlyViewedFile(paneId || MainViewManager.ACTIVE_PANE)); return result.promise(); } From 72d35ac9315de71ea671655ac54610826660b11c Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Wed, 6 Jan 2016 19:40:27 +0530 Subject: [PATCH 03/10] MRU List duplication fix when same document is being flipped --- src/view/MainViewManager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/MainViewManager.js b/src/view/MainViewManager.js index ef4e08b25f1..98194e067c9 100644 --- a/src/view/MainViewManager.js +++ b/src/view/MainViewManager.js @@ -830,6 +830,8 @@ define(function (require, exports, module) { sourcePane.moveView(file, destinationPane, destinationIndex) .done(function () { + // remove existing entry from mrulist for the same document if present + _removeFileFromMRU(destinationPane.id, file); // update the mru list _mruList.every(function (record) { if (record.file === file && record.paneId === sourcePane.id) { @@ -838,7 +840,6 @@ define(function (require, exports, module) { } return true; }); - exports.trigger("workingSetMove", file, sourcePane.id, destinationPane.id); result.resolve(); }); From 1cf30cd75b69e129e531f82a30cbba60d860ca23 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Thu, 7 Jan 2016 17:42:02 +0530 Subject: [PATCH 04/10] Fix for Hiding of all resizable divs during relaunch after setting no distractions. Should target only bottom-panel marked divs. --- src/utils/Resizer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/Resizer.js b/src/utils/Resizer.js index a4525620168..75248904ad0 100644 --- a/src/utils/Resizer.js +++ b/src/utils/Resizer.js @@ -225,7 +225,8 @@ define(function (require, exports, module) { resizerCSSPosition = direction === DIRECTION_HORIZONTAL ? "left" : "top", contentSizeFunction = direction === DIRECTION_HORIZONTAL ? $resizableElement.width : $resizableElement.height; - if (PreferencesManager.get(PREFS_PURE_CODE)) { + if (PreferencesManager.get(PREFS_PURE_CODE) && + ($element.hasClass("bottom-panel") || $element.hasClass("sidebar"))) { elementPrefs.visible = false; } From 41e0263cbb97900ee1a29d34308a7d0e0902b477 Mon Sep 17 00:00:00 2001 From: Pete Nykanen Date: Thu, 7 Jan 2016 20:03:02 +0200 Subject: [PATCH 05/10] Fix Flipview focus issues --- src/nls/root/strings.js | 1 + src/view/Pane.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index fa6feeb2572..bca4903bfcc 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -776,6 +776,7 @@ define({ "DESCRIPTION_OPEN_USER_PREFS_IN_SECOND_PANE" : "false to open user preferences file in left/top pane", "DESCRIPTION_MERGE_PANES_WHEN_LAST_FILE_CLOSED" : "true to collapse panes after the last file from the pane is closed via pane header close button", "DESCRIPTION_SHOW_PANE_HEADER_BUTTONS" : "Toggle when to show the close and flip-view buttons on the header.", + "DESCRIPTION_RETAIN_FOCUS_AFTER_FLIP" : "true to retain focus on the currently active pane, false to move focus to the new pane", "DEFAULT_PREFERENCES_JSON_HEADER_COMMENT" : "/*\n * This is a read-only file with the preferences supported\n * by {APP_NAME}.\n * Use this file as a reference to modify your preferences\n * file \"brackets.json\" opened in the other pane.\n * For more information on how to use preferences inside\n * {APP_NAME}, refer to the web page at https://github.com/adobe/brackets/wiki/How-to-Use-Brackets#preferences\n */", "DEFAULT_PREFERENCES_JSON_DEFAULT" : "Default", "DESCRIPTION_PURE_CODING_SURFACE" : "true to enable code only mode and hide all other UI elements in {APP_NAME}" diff --git a/src/view/Pane.js b/src/view/Pane.js index e0fe0397885..6f25d88e3e1 100644 --- a/src/view/Pane.js +++ b/src/view/Pane.js @@ -192,6 +192,12 @@ define(function (require, exports, module) { values: ["hover", "always", "never"] }); + // Define retainFocusAfterFlip, which controls which pane gets focus after a pane + // has been flipped. + PreferencesManager.definePreference("pane.retainFocusAfterFlip", "boolean", false, { + description: Strings.DESCRIPTION_RETAIN_FOCUS_AFTER_FLIP + }); + // Define mergePanesWhenLastFileClosed, which controls if a split view pane should be // closed when the last file is closed, skipping the "Open a file while this pane has focus" // step completely. @@ -229,6 +235,7 @@ define(function (require, exports, module) { // Setup the container and the element we're inserting var self = this, showPaneHeaderButtonsPref = PreferencesManager.get("pane.showPaneHeaderButtons"), + retainFocusAfterFlip = PreferencesManager.get("pane.retainFocusAfterFlip"), $el = $container.append(Mustache.render(paneTemplate, {id: id})).find("#" + id), $header = $el.find(".pane-header"), $headerText = $header.find(".pane-header-text"), @@ -246,11 +253,31 @@ define(function (require, exports, module) { var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE; var otherPane = MainViewManager._getPane(otherPaneId); + // currently active pane is not necessarily self.id as just clicking the button does not + // give focus to the pane. This way it is possible to flip multiple panes to the active one + // without losing focus. + var activePaneIdBeforeFlip = MainViewManager.getActivePaneId(); + MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () { CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath, paneId: otherPaneId}).always(function () { otherPane.trigger("viewListChange"); self.trigger("viewListChange"); + + // Defer the focusing until other focus events have occurred. + setTimeout(function () { + if (retainFocusAfterFlip) { + // Focus has most likely changed: give it back to the original pane. + var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip); + activePaneBeforeFlip.focus(); + self._lastFocusedElement = activePaneBeforeFlip.$el[0]; + MainViewManager.setActivePaneId(activePaneIdBeforeFlip); + } else { + // Other pane already has focus: update the Active Pane Id too. + MainViewManager.setActivePaneId(otherPaneId); + self._lastFocusedElement = otherPane.$el[0]; + } + }, 1); }); }); }); From 8bc2845d06bf3efa3b3d34ad860895b336f09ec4 Mon Sep 17 00:00:00 2001 From: Pete Nykanen Date: Thu, 7 Jan 2016 21:13:28 +0200 Subject: [PATCH 06/10] Remove the pane.retainFocusAfterFlip preference --- src/nls/root/strings.js | 1 - src/view/Pane.js | 25 ++----------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index bca4903bfcc..fa6feeb2572 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -776,7 +776,6 @@ define({ "DESCRIPTION_OPEN_USER_PREFS_IN_SECOND_PANE" : "false to open user preferences file in left/top pane", "DESCRIPTION_MERGE_PANES_WHEN_LAST_FILE_CLOSED" : "true to collapse panes after the last file from the pane is closed via pane header close button", "DESCRIPTION_SHOW_PANE_HEADER_BUTTONS" : "Toggle when to show the close and flip-view buttons on the header.", - "DESCRIPTION_RETAIN_FOCUS_AFTER_FLIP" : "true to retain focus on the currently active pane, false to move focus to the new pane", "DEFAULT_PREFERENCES_JSON_HEADER_COMMENT" : "/*\n * This is a read-only file with the preferences supported\n * by {APP_NAME}.\n * Use this file as a reference to modify your preferences\n * file \"brackets.json\" opened in the other pane.\n * For more information on how to use preferences inside\n * {APP_NAME}, refer to the web page at https://github.com/adobe/brackets/wiki/How-to-Use-Brackets#preferences\n */", "DEFAULT_PREFERENCES_JSON_DEFAULT" : "Default", "DESCRIPTION_PURE_CODING_SURFACE" : "true to enable code only mode and hide all other UI elements in {APP_NAME}" diff --git a/src/view/Pane.js b/src/view/Pane.js index 6f25d88e3e1..811267e913e 100644 --- a/src/view/Pane.js +++ b/src/view/Pane.js @@ -192,12 +192,6 @@ define(function (require, exports, module) { values: ["hover", "always", "never"] }); - // Define retainFocusAfterFlip, which controls which pane gets focus after a pane - // has been flipped. - PreferencesManager.definePreference("pane.retainFocusAfterFlip", "boolean", false, { - description: Strings.DESCRIPTION_RETAIN_FOCUS_AFTER_FLIP - }); - // Define mergePanesWhenLastFileClosed, which controls if a split view pane should be // closed when the last file is closed, skipping the "Open a file while this pane has focus" // step completely. @@ -235,7 +229,6 @@ define(function (require, exports, module) { // Setup the container and the element we're inserting var self = this, showPaneHeaderButtonsPref = PreferencesManager.get("pane.showPaneHeaderButtons"), - retainFocusAfterFlip = PreferencesManager.get("pane.retainFocusAfterFlip"), $el = $container.append(Mustache.render(paneTemplate, {id: id})).find("#" + id), $header = $el.find(".pane-header"), $headerText = $header.find(".pane-header-text"), @@ -253,11 +246,6 @@ define(function (require, exports, module) { var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE; var otherPane = MainViewManager._getPane(otherPaneId); - // currently active pane is not necessarily self.id as just clicking the button does not - // give focus to the pane. This way it is possible to flip multiple panes to the active one - // without losing focus. - var activePaneIdBeforeFlip = MainViewManager.getActivePaneId(); - MainViewManager._moveView(self.id, otherPaneId, currentFile).always(function () { CommandManager.execute(Commands.FILE_OPEN, {fullPath: currentFile.fullPath, paneId: otherPaneId}).always(function () { @@ -266,17 +254,8 @@ define(function (require, exports, module) { // Defer the focusing until other focus events have occurred. setTimeout(function () { - if (retainFocusAfterFlip) { - // Focus has most likely changed: give it back to the original pane. - var activePaneBeforeFlip = MainViewManager._getPane(activePaneIdBeforeFlip); - activePaneBeforeFlip.focus(); - self._lastFocusedElement = activePaneBeforeFlip.$el[0]; - MainViewManager.setActivePaneId(activePaneIdBeforeFlip); - } else { - // Other pane already has focus: update the Active Pane Id too. - MainViewManager.setActivePaneId(otherPaneId); - self._lastFocusedElement = otherPane.$el[0]; - } + MainViewManager.setActivePaneId(otherPaneId); + self._lastFocusedElement = otherPane.$el[0]; }, 1); }); }); From ddcbcca8f05c89806651103f37433769fb305b08 Mon Sep 17 00:00:00 2001 From: Pete Nykanen Date: Fri, 8 Jan 2016 23:38:03 +0200 Subject: [PATCH 07/10] Fix FlipView / WorkingSet / SplitViewSameDoc integration issues --- src/view/Pane.js | 49 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/view/Pane.js b/src/view/Pane.js index 811267e913e..9f9ac351f52 100644 --- a/src/view/Pane.js +++ b/src/view/Pane.js @@ -56,8 +56,8 @@ * * Pane Object Events: * - * - viewListChange - Whenever there is a file change to a file in the working set. These 2 events: `DocumentManger.pathRemove` - * and `DocumentManger.fileNameChange` will cause a `viewListChange` event so the WorkingSetView can update. + * - viewListChange - Whenever there is a file change to a file in the working set. These 2 events: `DocumentManager.pathRemove` + * and `DocumentManager.fileNameChange` will cause a `viewListChange` event so the WorkingSetView can update. * * - currentViewChange - Whenever the current view changes. * (e, newView:View, oldView:View) @@ -246,16 +246,33 @@ define(function (require, exports, module) { var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE; var otherPane = MainViewManager._getPane(otherPaneId); + // Currently active pane is not necessarily self.id as just clicking the button does not + // give focus to the pane. This way it is possible to flip multiple panes to the active one + // without losing focus. + var activePaneIdBeforeFlip = MainViewManager.getActivePaneId(); + var currentFileOnOtherPaneIndex = otherPane.findInViewList(currentFile.fullPath); + + // if the currentFile is already on other pane just close the current pane + 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 () { - otherPane.trigger("viewListChange"); + + 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 () { - MainViewManager.setActivePaneId(otherPaneId); - self._lastFocusedElement = otherPane.$el[0]; + // Focus has most likely changed: give it back to the original pane. + activePaneBeforeFlip.focus(); + self._lastFocusedElement = activePaneBeforeFlip.$el[0]; + MainViewManager.setActivePaneId(activePaneIdBeforeFlip); }, 1); }); }); @@ -564,23 +581,34 @@ define(function (require, exports, module) { // move the item in the working set and // open it in the destination pane openNextPromise.done(function () { + var viewListIndex = self.findInViewList(file.fullPath); + var shouldAddView = viewListIndex !== -1; + var view = self._views[file.fullPath]; + + // If the file isn't in working set, destroy the view and delete it from + // source pane's view map and return as solved + if (!shouldAddView) { + if (view) { + self._doDestroyView(view); + } + return result.resolve(); + } + // Remove file from all 3 view lists - self._viewList.splice(self.findInViewList(file.fullPath), 1); + self._viewList.splice(viewListIndex, 1); self._viewListMRUOrder.splice(self.findInViewListMRUOrder(file.fullPath), 1); self._viewListAddedOrder.splice(self.findInViewListAddedOrder(file.fullPath), 1); // insert the view into the working set destinationPane._addToViewList(file, _makeIndexRequestObject(true, destinationIndex)); - //move the view, - var view = self._views[file.fullPath]; - // if we had a view, it had previously been opened - // otherwise, the file was in the working set unopened + // otherwise, the file was in the working set unopened if (view) { // delete it from the source pane's view map and add it to the destination pane's view map delete self._views[file.fullPath]; destinationPane.addView(view, !destinationPane.getCurrentlyViewedFile()); + // we're done result.resolve(); } else if (!destinationPane.getCurrentlyViewedFile()) { @@ -819,7 +847,6 @@ define(function (require, exports, module) { */ Pane.prototype.addToViewList = function (file, index) { var indexRequested = (index !== undefined && index !== null && index >= 0 && index < this._viewList.length); - this._addToViewList(file, _makeIndexRequestObject(indexRequested, index)); if (!indexRequested) { From 2c058f148733636c64baaddec8ba6fffc66e4120 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Mon, 11 Jan 2016 13:33:04 +0530 Subject: [PATCH 08/10] Prevent same doc flip to avoid document corruption --- src/view/Pane.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/view/Pane.js b/src/view/Pane.js index 9f9ac351f52..3e8156a04b9 100644 --- a/src/view/Pane.js +++ b/src/view/Pane.js @@ -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 From 953d97e7c5b1e7148f20bbbad6cca77cfd9e01a5 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Mon, 11 Jan 2016 19:32:06 +0530 Subject: [PATCH 09/10] Fix for the focus issue while switching focus between inline editors hosted under split views for the same doc. --- src/editor/Editor.js | 14 ++++++++++++-- src/editor/EditorManager.js | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 622040b169a..f615af48d82 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -331,6 +331,9 @@ define(function (require, exports, module) { // To track which pane the editor is being attached to if it's a full editor this._paneId = null; + + // To track the parent editor ( host editor at that time of creation) of an inline editor + this._hostEditor = null; // Editor supplies some standard keyboard behavior extensions of its own var codeMirrorKeyMap = { @@ -983,10 +986,17 @@ define(function (require, exports, module) { // Convert CodeMirror onFocus events to EditorManager activeEditorChanged this._codeMirror.on("focus", function () { + if (self._hostEditor) { + // Mark the host editor as the master editor for the hosting document + self._hostEditor.document._toggleMasterEditor(self._hostEditor); + } else { + // Set this full editor as master editor for the document + self.document._toggleMasterEditor(self); + } + self._focused = true; self.trigger("focus", self); - // Set this full editor as master editor for the document - self.document._toggleMasterEditor(self); + }); this._codeMirror.on("blur", function () { diff --git a/src/editor/EditorManager.js b/src/editor/EditorManager.js index e2b5f6b7ad8..299d4354a48 100644 --- a/src/editor/EditorManager.js +++ b/src/editor/EditorManager.js @@ -505,6 +505,7 @@ define(function (require, exports, module) { // first and showing it after the visible range is set, we avoid that initial render. $(inlineContent).hide(); var inlineEditor = _createEditorForDocument(doc, false, inlineContent, range); + inlineEditor._hostEditor = getCurrentFullEditor(); $(inlineContent).show(); return { content: inlineContent, editor: inlineEditor }; From d72753b6b8bcc575f6e3cbbb96b4795a037a7740 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Tue, 12 Jan 2016 16:16:33 +0530 Subject: [PATCH 10/10] Fix for same doc drag across panes in working set and same doc flip using pane header. --- src/project/WorkingSetView.js | 37 ++++++++++++++++------------- src/view/Pane.js | 44 ++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/project/WorkingSetView.js b/src/project/WorkingSetView.js index a9496029083..e92cdb205ed 100644 --- a/src/project/WorkingSetView.js +++ b/src/project/WorkingSetView.js @@ -788,22 +788,27 @@ define(function (require, exports, module) { MainViewManager._moveWorkingSetItem(sourceView.paneId, startingIndex, $el.index()); postDropCleanup(); } else { - // item was dragged to another working set - MainViewManager._moveView(sourceView.paneId, currentView.paneId, sourceFile, $el.index()) - .always(function () { - // if the current document was dragged to another working set - // then reopen it to make it the currently selected file - if (draggingCurrentFile) { - CommandManager - .execute(Commands.FILE_OPEN, {fullPath: sourceFile.fullPath, - paneId: currentView.paneId}) - .always(function () { - postDropCleanup(); - }); - } else { - postDropCleanup(); - } - }); + // If the same doc view is present in the destination pane prevent drop + if (!MainViewManager._getPane(currentView.paneId).getViewForPath(sourceFile.fullPath)) { + // item was dragged to another working set + MainViewManager._moveView(sourceView.paneId, currentView.paneId, sourceFile, $el.index()) + .always(function () { + // if the current document was dragged to another working set + // then reopen it to make it the currently selected file + if (draggingCurrentFile) { + CommandManager + .execute(Commands.FILE_OPEN, {fullPath: sourceFile.fullPath, + paneId: currentView.paneId}) + .always(function () { + postDropCleanup(); + }); + } else { + postDropCleanup(); + } + }); + } else { + postDropCleanup(); + } } } diff --git a/src/view/Pane.js b/src/view/Pane.js index 3e8156a04b9..5bae3512bd7 100644 --- a/src/view/Pane.js +++ b/src/view/Pane.js @@ -245,6 +245,11 @@ define(function (require, exports, module) { var currentFile = self.getCurrentlyViewedFile(); var otherPaneId = self.id === FIRST_PANE ? SECOND_PANE : FIRST_PANE; var otherPane = MainViewManager._getPane(otherPaneId); + + // If the same doc view is present in the destination pane prevent flip + if (otherPane.getViewForPath(currentFile.fullPath)) { + return; + } // Currently active pane is not necessarily self.id as just clicking the button does not // give focus to the pane. This way it is possible to flip multiple panes to the active one @@ -257,28 +262,25 @@ define(function (require, exports, module) { CommandManager.execute(Commands.FILE_CLOSE, {File: currentFile, paneId: self.id}); } - // 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); - }); + 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