diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 2af75899659..cf11bc0cd15 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -291,8 +291,8 @@ 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) { - result.resolve(MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE)); + if (MainViewManager.getCurrentlyViewedPath(paneId || MainViewManager.ACTIVE_PANE) === fullPath) { + result.resolve(MainViewManager.getCurrentlyViewedFile(paneId || MainViewManager.ACTIVE_PANE)); return result.promise(); } 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 }; 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({ 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/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; } 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(); }); diff --git a/src/view/Pane.js b/src/view/Pane.js index e0fe0397885..5bae3512bd7 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) @@ -245,12 +245,40 @@ 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 + // 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 () { + // Focus has most likely changed: give it back to the original pane. + activePaneBeforeFlip.focus(); + self._lastFocusedElement = activePaneBeforeFlip.$el[0]; + MainViewManager.setActivePaneId(activePaneIdBeforeFlip); + }, 1); }); }); }); @@ -558,23 +586,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()) { @@ -813,7 +852,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) {