提交 e2c3e4b5 编写于 作者: B Benjamin Pasero

do not eagerly fill options when opening a side editor

上级 e8ddfed2
......@@ -19,6 +19,7 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {IHistoryService} from 'vs/workbench/services/history/common/history';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
export class SplitEditorAction extends Action {
......@@ -47,6 +48,16 @@ export class SplitEditorAction extends Action {
return TPromise.as(true);
}
// Options
let options: EditorOptions;
if (activeEditor instanceof BaseTextEditor) {
options = new TextEditorOptions();
(<TextEditorOptions>options).viewState(activeEditor.getControl().saveViewState());
} else {
options = new EditorOptions();
}
options.pinned = true;
// Count editors
let visibleEditors = this.editorService.getVisibleEditors();
let editorCount = visibleEditors.length;
......@@ -69,9 +80,7 @@ export class SplitEditorAction extends Action {
// Push the center group to the right to make room for the splitted input
else if (activeEditor.position === Position.LEFT) {
let options = new TextEditorOptions();
options.preserveFocus = true;
options.pinned = true;
return this.editorService.openEditor(activeEditor.input, options, Position.RIGHT).then(() => {
this.editorGroupService.moveGroup(Position.RIGHT, Position.CENTER);
......@@ -82,7 +91,7 @@ export class SplitEditorAction extends Action {
// Only split if we have a target position to split to
if (typeof targetPosition === 'number') {
return this.editorService.openEditor(activeEditor.input, EditorOptions.create({ pinned: true }), targetPosition);
return this.editorService.openEditor(activeEditor.input, options, targetPosition);
}
return TPromise.as(true);
......
......@@ -15,14 +15,12 @@ import nls = require('vs/nls');
import strings = require('vs/base/common/strings');
import arrays = require('vs/base/common/arrays');
import types = require('vs/base/common/types');
import {IEditorViewState, IEditor} from 'vs/editor/common/editorCommon';
import errors = require('vs/base/common/errors');
import {Scope as MementoScope} from 'vs/workbench/common/memento';
import {Scope} from 'vs/workbench/browser/actionBarRegistry';
import {Part} from 'vs/workbench/browser/part';
import {IEditorRegistry, Extensions as EditorExtensions, BaseEditor, EditorDescriptor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorInput, EditorOptions, TextEditorOptions, ConfirmResult, EditorInputEvent} from 'vs/workbench/common/editor';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
import {EditorInput, EditorOptions, ConfirmResult, EditorInputEvent} from 'vs/workbench/common/editor';
import {SideBySideEditorControl, Rochade, ISideBySideEditorControl, ProgressState} from 'vs/workbench/browser/parts/editor/sideBySideEditorControl';
import {WorkbenchProgressService} from 'vs/workbench/services/progress/browser/progressService';
import {GroupArrangement} from 'vs/workbench/services/editor/common/editorService';
......@@ -201,12 +199,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Opened to the side
if (position !== Position.LEFT) {
// Log side by side use
this.telemetryService.publicLog('workbenchSideEditorOpened', { position: position });
// Determine options if the editor opens to the side by looking at same input already opened
options = this.findSideOptions(input, options, position);
}
// Open through UI
......@@ -1159,58 +1152,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return arg1;
}
private findSideOptions(input: EditorInput, options: EditorOptions, position: Position): EditorOptions {
if (
(this.visibleEditors[position] && input.matches(this.visibleEditors[position].input)) || // Return early if the input is already showing at the position
(options instanceof TextEditorOptions && (<TextEditorOptions>options).hasOptionsDefined()) // Return early if explicit text options are defined
) {
return options;
}
// Otherwise try to copy viewstate over from an existing opened editor with same input
let viewState: IEditorViewState = null;
let editors = this.getVisibleEditors();
for (let i = 0; i < editors.length; i++) {
let editor = editors[i];
if (!(editor instanceof BaseTextEditor)) {
continue; // Only works with text editors
}
// Found a match
if (input.matches(editor.input)) {
let codeEditor = <IEditor>editor.getControl();
viewState = <IEditorViewState>codeEditor.saveViewState();
break;
}
}
// Found view state
if (viewState) {
let textEditorOptions: TextEditorOptions = null;
// Merge into existing text editor options if given
if (options instanceof TextEditorOptions) {
textEditorOptions = <TextEditorOptions>options;
textEditorOptions.viewState(viewState);
return textEditorOptions;
}
// Otherwise create new
textEditorOptions = new TextEditorOptions();
textEditorOptions.viewState(viewState);
if (options) {
textEditorOptions.mixin(options);
}
return textEditorOptions;
}
return options;
}
private startDelayedCloseEditorsFromInputDispose(): void {
// To prevent race conditions, we call the close in a timeout because it can well be
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册