allow Text Editor to show up in focusedView (#195181)

This commit is contained in:
Megan Rogge
2023-10-12 08:58:00 +02:00
committed by GitHub
parent 901ac65ea9
commit 0719762057
2 changed files with 41 additions and 4 deletions
@@ -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<unknown>(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<string>(WindowSettingNames.title);
const titleSeparator = this.configurationService.inspect<string>(WindowSettingNames.titleSeparator);
return title.value !== title.defaultValue || titleSeparator.value !== titleSeparator.defaultValue;
}
}
@@ -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<T extends IView>(id: string, focus?: boolean): Promise<T | null> {