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

Split View (Same Document) #11820

Merged
merged 16 commits into from Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 38 additions & 6 deletions src/document/Document.js
Expand Up @@ -83,6 +83,11 @@ define(function (require, exports, module) {

EventDispatcher.makeEventDispatcher(Document.prototype);

/**
* list of editors who were initialized as master editors for this doc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: First letter of the first word in a sentence should be capitalized.

*/
Document.prototype._associatedFullEditors = [];

/**
* Number of clients who want this Document to stay alive. The Document is listed in
* DocumentManager._openDocuments whenever refCount > 0.
Expand Down Expand Up @@ -196,12 +201,15 @@ define(function (require, exports, module) {
*/
Document.prototype._makeEditable = function (masterEditor) {
if (this._masterEditor) {
console.error("Document is already editable");
} else {
this._text = null;
this._masterEditor = masterEditor;
masterEditor.on("change", this._handleEditorChange.bind(this));
//Already a master editor is associated , so preserve the old editor in list of full editors
if(this._associatedFullEditors.indexOf(this._masterEditor) < 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use Brackets with JSLint enabled when contributing to Brackets. Please re-check your code. In this specific case, there's a space missing between if and ( which JSLint would complain about.

this._associatedFullEditors.push(this._masterEditor);
}
}

this._text = null;
this._masterEditor = masterEditor;
masterEditor.on("change", this._handleEditorChange.bind(this));
};

/**
Expand All @@ -215,7 +223,31 @@ define(function (require, exports, module) {
} else {
// _text represents the raw text, so fetch without normalized line endings
this._text = this.getText(true);
this._masterEditor = null;
this._associatedFullEditors.splice(this._associatedFullEditors.indexOf(this._masterEditor),1);

//Identify the most recently created full editor before this and set that as new master editor
if(this._associatedFullEditors.length > 0){
this._masterEditor = this._associatedFullEditors[this._associatedFullEditors.length - 1];
} else {
this._masterEditor = null;
}
}
};

/**
* Toggles the master editor from a pool of full editors which has gained focus
* To be used internally by Editor only
*/
Document.prototype._toggleMasterEditor = function (masterEditor) {
//Do a check before processing the request to ensure inline editors are not being set as master editor
if(this._associatedFullEditors.indexOf(masterEditor) >= 0){
if (this._masterEditor) {
//Already a master editor is associated , so preserve the old editor in list of editors
if(this._associatedFullEditors.indexOf(this._masterEditor) < 0){
this._associatedFullEditors.push(this._masterEditor);
}
}
this._masterEditor = masterEditor;
}
};

Expand Down
1 change: 1 addition & 0 deletions src/editor/Editor.js
Expand Up @@ -961,6 +961,7 @@ define(function (require, exports, module) {
this._codeMirror.on("focus", function () {
self._focused = true;
self.trigger("focus", self);
self.document._toggleMasterEditor(self);//Added to toggle fulleditors as master editor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after // in comments. Here and multiple other places. Just look around to see what the comments should like.

});

this._codeMirror.on("blur", function () {
Expand Down
10 changes: 4 additions & 6 deletions src/editor/EditorManager.js
Expand Up @@ -542,7 +542,9 @@ define(function (require, exports, module) {
var createdNewEditor = false,
editor = document._masterEditor;

if (!editor) {
//Check if a master editor is not set already or the current master editor doesn't belong
//to the pane container requested - to support creation of multiple full editors
if (!editor || editor.$el.parent()[0] !== pane.$content[0]) {
// Performance (see #4757) Chrome wastes time messing with selection
// that will just be changed at end, so clear it for now
if (window.getSelection && window.getSelection().empty) { // Chrome
Expand All @@ -552,11 +554,7 @@ define(function (require, exports, module) {
// Editor doesn't exist: populate a new Editor with the text
editor = _createFullEditorForDocument(document, pane, editorOptions);
createdNewEditor = true;
} else if (editor.$el.parent()[0] !== pane.$content[0]) {
// editor does exist but is not a child of the pane so add it to the
// pane (which will switch the view's container as well)
pane.addView(editor);
}
}

// show the view
pane.showView(editor);
Expand Down
42 changes: 0 additions & 42 deletions src/view/MainViewManager.js
Expand Up @@ -706,15 +706,6 @@ define(function (require, exports, module) {
if (!pane) {
throw new Error("invalid pane id: " + paneId);
}

if (findInWorkingSet(ALL_PANES, file.fullPath) !== -1) {
return;
}

// if it's already open in another pane, then just use that pane
if (existingPaneId && existingPaneId !== pane.id) {
pane = _getPane(existingPaneId);
}

var result = pane.reorderItem(file, index, force),
entry = _makeMRUListEntry(file, pane.id);
Expand Down Expand Up @@ -1188,14 +1179,6 @@ define(function (require, exports, module) {
var options = optionsIn || {},
currentPaneId = _getPaneIdForPath(doc.file.fullPath);

if (currentPaneId) {
// If the doc is open in another pane then switch to that pane and call open document
// which will really just show the view as it has always done we could just
// do pane.showView(doc._masterEditor) in that case but Editor Manager may do some
// state syncing
paneId = currentPaneId;
}

var pane = _getPane(paneId);

// If file is untitled or otherwise not within project tree, add it to
Expand Down Expand Up @@ -1237,31 +1220,6 @@ define(function (require, exports, module) {
}

var currentPaneId = _getPaneIdForPath(file.fullPath);

if (currentPaneId) {
// Warn user (only once) when file is already open in another view
if (!PreferencesManager.getViewState("splitview.multipane-info") &&
currentPaneId !== _resolvePaneId(paneId)) {
PreferencesManager.setViewState("splitview.multipane-info", true);

// File tree also executes single-click code prior to executing double-click
// code, so delay showing modal dialog to prevent eating second click
window.setTimeout(function () {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.SPLITVIEW_INFO_TITLE,
Strings.SPLITVIEW_MULTIPANE_WARNING
);
}, 500);
}

// If the doc is open in another pane
// then switch to that pane and call open document
// which will really just show the view as it has always done
// we could just do pane.showView(doc._masterEditor) in that
// case but Editor Manager may do some state syncing
paneId = currentPaneId;
}

// See if there is already a view for the file
var pane = _getPane(paneId);
Expand Down
2 changes: 1 addition & 1 deletion src/view/Pane.js
Expand Up @@ -647,7 +647,7 @@ define(function (require, exports, module) {
*/
Pane.prototype._canAddFile = function (file) {
return ((this._views.hasOwnProperty(file.fullPath) && this.findInViewList(file.fullPath) === -1) ||
(!MainViewManager._getPaneIdForPath(file.fullPath)));
(MainViewManager._getPaneIdForPath(file.fullPath) !== this.id));
};

/**
Expand Down