提交 93906af3 编写于 作者: B Benjamin Pasero

split action: needs to respect context if provided

上级 e2c3e4b5
...@@ -35,24 +35,29 @@ export class SplitEditorAction extends Action { ...@@ -35,24 +35,29 @@ export class SplitEditorAction extends Action {
super(id, label, 'split-editor-action'); super(id, label, 'split-editor-action');
} }
public run(): TPromise<any> { public run(context: IEditorContext): TPromise<any> {
let editorToSplit: IEditor;
if (context) {
editorToSplit = this.editorService.getVisibleEditors()[this.editorGroupService.getStacksModel().positionOfGroup(context.group)];
} else {
editorToSplit = this.editorService.getActiveEditor();
}
// Can only split with active editor // Can only split with target editor
let activeEditor = this.editorService.getActiveEditor(); if (!editorToSplit) {
if (!activeEditor) {
return TPromise.as(true); return TPromise.as(true);
} }
// Return if the editor to split does not support split editing // Return if the editor to split does not support split editing
if (!(<BaseEditor>activeEditor).supportsSplitEditor()) { if (!(<BaseEditor>editorToSplit).supportsSplitEditor()) {
return TPromise.as(true); return TPromise.as(true);
} }
// Options // Options
let options: EditorOptions; let options: EditorOptions;
if (activeEditor instanceof BaseTextEditor) { if (editorToSplit instanceof BaseTextEditor) {
options = new TextEditorOptions(); options = new TextEditorOptions();
(<TextEditorOptions>options).viewState(activeEditor.getControl().saveViewState()); (<TextEditorOptions>options).viewState(editorToSplit.getControl().saveViewState());
} else { } else {
options = new EditorOptions(); options = new EditorOptions();
} }
...@@ -74,15 +79,15 @@ export class SplitEditorAction extends Action { ...@@ -74,15 +79,15 @@ export class SplitEditorAction extends Action {
case 2: case 2:
// Continue splitting to the right // Continue splitting to the right
if (activeEditor.position === Position.CENTER) { if (editorToSplit.position === Position.CENTER) {
targetPosition = Position.RIGHT; targetPosition = Position.RIGHT;
} }
// Push the center group to the right to make room for the splitted input // Push the center group to the right to make room for the splitted input
else if (activeEditor.position === Position.LEFT) { else if (editorToSplit.position === Position.LEFT) {
options.preserveFocus = true; options.preserveFocus = true;
return this.editorService.openEditor(activeEditor.input, options, Position.RIGHT).then(() => { return this.editorService.openEditor(editorToSplit.input, options, Position.RIGHT).then(() => {
this.editorGroupService.moveGroup(Position.RIGHT, Position.CENTER); this.editorGroupService.moveGroup(Position.RIGHT, Position.CENTER);
this.editorGroupService.focusGroup(Position.CENTER); this.editorGroupService.focusGroup(Position.CENTER);
}); });
...@@ -91,7 +96,7 @@ export class SplitEditorAction extends Action { ...@@ -91,7 +96,7 @@ export class SplitEditorAction extends Action {
// Only split if we have a target position to split to // Only split if we have a target position to split to
if (typeof targetPosition === 'number') { if (typeof targetPosition === 'number') {
return this.editorService.openEditor(activeEditor.input, options, targetPosition); return this.editorService.openEditor(editorToSplit.input, options, targetPosition);
} }
return TPromise.as(true); return TPromise.as(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册