From 6a43144013c450715aeca11f468d9744586a1685 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 19 Nov 2015 10:33:42 +0100 Subject: [PATCH] introduce forceActive flag as option for opening editors (fixes #182) --- src/vs/platform/editor/common/editor.ts | 6 ++++++ src/vs/workbench/browser/parts/editor/editorPart.ts | 5 +++++ src/vs/workbench/common/editor.ts | 9 ++++++++- src/vs/workbench/parts/debug/browser/debugService.ts | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index eb6a2dc7445..753227b31fa 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -72,6 +72,12 @@ export interface ITextInput { * Will open the editor but not move keyboard focus into the editor. */ preserveFocus?: boolean; + + /** + * Ensures that the editor is being activated even if the input is already showing. This only applies + * if there is more than one editor open already and preserveFocus is set to false. + */ + forceActive?: boolean; }; } diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 3c519aa0815..eb6c62098d0 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -652,6 +652,11 @@ export class EditorPart extends Part implements IEditorPart { editor.focus(); } + // Otherwise check if we want to activate + else if (options && options.forceActive) { + this.sideBySideControl.setActive(editor); + } + // Progress Done this.sideBySideControl.getProgressBar(position).done().getContainer().hide(); diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 6ece38dd377..fe16a8e8d12 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -213,6 +213,12 @@ export class EditorOptions implements IEditorOptions { */ public forceOpen: boolean; + /** + * Ensures that the editor is being activated even if the input is already showing. This only applies + * if there is more than one editor open already and preserveFocus is set to false. + */ + public forceActive: boolean; + /** * Returns true if this options is identical to the otherOptions. */ @@ -258,9 +264,10 @@ export class TextEditorOptions extends EditorOptions { /** * Helper to create TextEditorOptions inline. */ - public static create(settings: { preserveFocus?: boolean; forceOpen?: boolean; selection?: IRange }): TextEditorOptions { + public static create(settings: { preserveFocus?: boolean; forceOpen?: boolean; forceActive?: boolean; selection?: IRange }): TextEditorOptions { let options = new TextEditorOptions(); options.preserveFocus = settings.preserveFocus; + options.forceActive = settings.forceActive; options.forceOpen = settings.forceOpen; if (settings.selection) { diff --git a/src/vs/workbench/parts/debug/browser/debugService.ts b/src/vs/workbench/parts/debug/browser/debugService.ts index 8c3cc714386..d277212468c 100644 --- a/src/vs/workbench/parts/debug/browser/debugService.ts +++ b/src/vs/workbench/parts/debug/browser/debugService.ts @@ -663,7 +663,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService if (control) { control.revealLineInCenterIfOutsideViewport(lineNumber); control.setSelection({ startLineNumber: lineNumber, startColumn: 1, endLineNumber: lineNumber, endColumn: 1 }); - return this.editorService.openEditor(visibleEditors[i].input, wbeditorcommon.TextEditorOptions.create({ preserveFocus: preserveFocus }), visibleEditors[i].position); + return this.editorService.openEditor(visibleEditors[i].input, wbeditorcommon.TextEditorOptions.create({ preserveFocus: preserveFocus, forceActive: true }), visibleEditors[i].position); } return Promise.as(null);