From 0719762057b11690a8d04de3dcfcf50a6d4fbbff Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 11 Oct 2023 23:58:00 -0700 Subject: [PATCH] allow `Text Editor` to show up in `focusedView` (#195181) --- .../browser/parts/titlebar/windowTitle.ts | 38 ++++++++++++++++++- .../browser/parts/views/viewsService.ts | 7 +++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/browser/parts/titlebar/windowTitle.ts b/src/vs/workbench/browser/parts/titlebar/windowTitle.ts index ee3683fec4c..a723be76707 100644 --- a/src/vs/workbench/browser/parts/titlebar/windowTitle.ts +++ b/src/vs/workbench/browser/parts/titlebar/windowTitle.ts @@ -25,6 +25,7 @@ import { Schemas } from 'vs/base/common/network'; import { getVirtualWorkspaceLocation } from 'vs/platform/workspace/common/virtualWorkspace'; import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; import { IViewsService } from 'vs/workbench/common/views'; +import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; const enum WindowSettingNames { titleSeparator = 'window.titleSeparator', @@ -45,6 +46,7 @@ export class WindowTitle extends Disposable { readonly onDidChange = this.onDidChangeEmitter.event; private title: string | undefined; + private titleIncludesFocusedView: boolean = false; constructor( @IConfigurationService protected readonly configurationService: IConfigurationService, @@ -58,6 +60,8 @@ export class WindowTitle extends Disposable { @IViewsService private readonly viewsService: IViewsService ) { super(); + + this.updateTitleIncludesFocusedView(); this.registerListeners(); } @@ -77,15 +81,28 @@ export class WindowTitle extends Disposable { this._register(this.contextService.onDidChangeWorkspaceName(() => this.titleUpdater.schedule())); this._register(this.labelService.onDidChangeFormatters(() => this.titleUpdater.schedule())); this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.titleUpdater.schedule())); - this._register(this.viewsService.onDidChangeFocusedView(() => this.titleUpdater.schedule())); + this._register(this.viewsService.onDidChangeFocusedView(() => { + if (this.titleIncludesFocusedView) { + this.titleUpdater.schedule(); + } + })); } private onConfigurationChanged(event: IConfigurationChangeEvent): void { + if (event.affectsConfiguration(WindowSettingNames.title)) { + this.updateTitleIncludesFocusedView(); + } + if (event.affectsConfiguration(WindowSettingNames.title) || event.affectsConfiguration(WindowSettingNames.titleSeparator)) { this.titleUpdater.schedule(); } } + private updateTitleIncludesFocusedView(): void { + const titleTemplate = this.configurationService.getValue(WindowSettingNames.title); + this.titleIncludesFocusedView = typeof titleTemplate === 'string' && titleTemplate.includes('${focusedView}'); + } + private onActiveEditorChange(): void { // Dispose old listeners @@ -100,6 +117,22 @@ export class WindowTitle extends Disposable { this.activeEditorListeners.add(activeEditor.onDidChangeDirty(() => this.titleUpdater.schedule())); this.activeEditorListeners.add(activeEditor.onDidChangeLabel(() => this.titleUpdater.schedule())); } + + // Apply listeners for tracking focused code editor + if (this.titleIncludesFocusedView) { + const activeTextEditorControl = this.editorService.activeTextEditorControl; + const textEditorControls: ICodeEditor[] = []; + if (isCodeEditor(activeTextEditorControl)) { + textEditorControls.push(activeTextEditorControl); + } else if (isDiffEditor(activeTextEditorControl)) { + textEditorControls.push(activeTextEditorControl.getOriginalEditor(), activeTextEditorControl.getModifiedEditor()); + } + + for (const textEditorControl of textEditorControls) { + this.activeEditorListeners.add(textEditorControl.onDidBlurEditorText(() => this.titleUpdater.schedule())); + this.activeEditorListeners.add(textEditorControl.onDidFocusEditorText(() => this.titleUpdater.schedule())); + } + } } private doUpdateTitle(): void { @@ -189,7 +222,7 @@ export class WindowTitle extends Disposable { * {appName}: e.g. VS Code * {remoteName}: e.g. SSH * {dirty}: indicator - * {focusedView}L e.g. Terminal + * {focusedView}: e.g. Terminal * {separator}: conditional separator */ getWindowTitle(): string { @@ -277,6 +310,7 @@ export class WindowTitle extends Disposable { isCustomTitleFormat(): boolean { const title = this.configurationService.inspect(WindowSettingNames.title); const titleSeparator = this.configurationService.inspect(WindowSettingNames.titleSeparator); + return title.value !== title.defaultValue || titleSeparator.value !== titleSeparator.defaultValue; } } diff --git a/src/vs/workbench/browser/parts/views/viewsService.ts b/src/vs/workbench/browser/parts/views/viewsService.ts index 22eb80ff787..0907c9e8783 100644 --- a/src/vs/workbench/browser/parts/views/viewsService.ts +++ b/src/vs/workbench/browser/parts/views/viewsService.ts @@ -32,6 +32,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor import { FilterViewPaneContainer } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { ICommandActionTitle, ILocalizedString } from 'vs/platform/action/common/action'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; export class ViewsService extends Disposable implements IViewsService { @@ -56,7 +57,8 @@ export class ViewsService extends Disposable implements IViewsService { @IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService, @IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService, @IContextKeyService private readonly contextKeyService: IContextKeyService, - @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService + @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, + @IEditorService private readonly editorService: IEditorService ) { super(); @@ -239,7 +241,8 @@ export class ViewsService extends Disposable implements IViewsService { getFocusedViewName(): string { const viewId: string = this.contextKeyService.getContextKeyValue(FocusedViewContext.key) ?? ''; - return this.viewDescriptorService.getViewDescriptorById(viewId.toString())?.name?.value ?? ''; + const textEditorFocused = this.editorService.activeTextEditorControl?.hasTextFocus() ? localize('editor', "Text Editor") : undefined; + return this.viewDescriptorService.getViewDescriptorById(viewId.toString())?.name?.value ?? textEditorFocused ?? ''; } async openView(id: string, focus?: boolean): Promise {