diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 90a181405aa0fcbd955a09a6393fe40c8b78e630..4b165a4f9bbeb0248a8f4515ca84a5b0ff02872e 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -35,24 +35,29 @@ export class SplitEditorAction extends Action { super(id, label, 'split-editor-action'); } - public run(): TPromise { + public run(context: IEditorContext): TPromise { + 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 - let activeEditor = this.editorService.getActiveEditor(); - if (!activeEditor) { + // Can only split with target editor + if (!editorToSplit) { return TPromise.as(true); } // Return if the editor to split does not support split editing - if (!(activeEditor).supportsSplitEditor()) { + if (!(editorToSplit).supportsSplitEditor()) { return TPromise.as(true); } // Options let options: EditorOptions; - if (activeEditor instanceof BaseTextEditor) { + if (editorToSplit instanceof BaseTextEditor) { options = new TextEditorOptions(); - (options).viewState(activeEditor.getControl().saveViewState()); + (options).viewState(editorToSplit.getControl().saveViewState()); } else { options = new EditorOptions(); } @@ -74,15 +79,15 @@ export class SplitEditorAction extends Action { case 2: // Continue splitting to the right - if (activeEditor.position === Position.CENTER) { + if (editorToSplit.position === Position.CENTER) { targetPosition = Position.RIGHT; } // 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; - 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.focusGroup(Position.CENTER); }); @@ -91,7 +96,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, options, targetPosition); + return this.editorService.openEditor(editorToSplit.input, options, targetPosition); } return TPromise.as(true);