Skip to content

Commit 5a167bb

Browse files
committed
editor: conoslidte computing of editor aria labels and use 'preview' for preivew tabs and pinned
1 parent 1ea6771 commit 5a167bb

8 files changed

Lines changed: 38 additions & 42 deletions

File tree

src/vs/workbench/browser/parts/editor/editor.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ISerializableView } from 'vs/base/browser/ui/grid/grid';
1414
import { getCodeEditor } from 'vs/editor/browser/editorBrowser';
1515
import { IEditorOptions } from 'vs/platform/editor/common/editor';
1616
import { IEditorService, IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
17+
import { localize } from 'vs/nls';
1718

1819
export const EDITOR_TITLE_HEIGHT = 35;
1920

@@ -41,6 +42,24 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
4142
splitSizing: 'distribute'
4243
};
4344

45+
export function computeEditorAriaLabel(input: IEditorInput, group: IEditorGroup | undefined, groupCount: number): string {
46+
let ariaLabel = input.ariaLabel;
47+
if (group && !group.isPinned(input)) {
48+
ariaLabel += localize('preview', ", preview");
49+
}
50+
if (group && group.isSticky(input)) {
51+
ariaLabel += localize('pinned', ", pinned");
52+
}
53+
// Apply group information to help identify in
54+
// which group we are (only if more than one group
55+
// is actually opened)
56+
if (group && groupCount > 1) {
57+
ariaLabel += ', ' + group.ariaLabel;
58+
}
59+
60+
return ariaLabel;
61+
}
62+
4463
export function impactsEditorPartOptions(event: IConfigurationChangeEvent): boolean {
4564
return event.affectsConfiguration('workbench.editor') || event.affectsConfiguration('workbench.iconTheme');
4665
}

src/vs/workbench/browser/parts/editor/tabsTitleControl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import { ResourcesDropHandler, DraggedEditorIdentifier, DraggedEditorGroupIdenti
3131
import { Color } from 'vs/base/common/color';
3232
import { INotificationService } from 'vs/platform/notification/common/notification';
3333
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
34-
import { MergeGroupMode, IMergeGroupOptions, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
34+
import { MergeGroupMode, IMergeGroupOptions, GroupsArrangement, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
3535
import { addClass, addDisposableListener, hasClass, EventType, EventHelper, removeClass, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode } from 'vs/base/browser/dom';
3636
import { localize } from 'vs/nls';
37-
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl, EDITOR_TITLE_HEIGHT } from 'vs/workbench/browser/parts/editor/editor';
37+
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl, EDITOR_TITLE_HEIGHT, computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor';
3838
import { CloseOneEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
3939
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
4040
import { BreadcrumbsControl } from 'vs/workbench/browser/parts/editor/breadcrumbsControl';
@@ -102,7 +102,8 @@ export class TabsTitleControl extends TitleControl {
102102
@IConfigurationService configurationService: IConfigurationService,
103103
@IFileService fileService: IFileService,
104104
@IEditorService private readonly editorService: EditorServiceImpl,
105-
@IPathService private readonly pathService: IPathService
105+
@IPathService private readonly pathService: IPathService,
106+
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService
106107
) {
107108
super(parent, accessor, group, contextMenuService, instantiationService, contextKeyService, keybindingService, telemetryService, notificationService, menuService, quickInputService, themeService, extensionService, configurationService, fileService);
108109

@@ -881,14 +882,13 @@ export class TabsTitleControl extends TitleControl {
881882
private computeTabLabels(): void {
882883
const { labelFormat } = this.accessor.partOptions;
883884
const { verbosity, shortenDuplicates } = this.getLabelConfigFlags(labelFormat);
884-
885885
// Build labels and descriptions for each editor
886886
const labels = this.group.editors.map(editor => ({
887887
editor,
888888
name: editor.getName(),
889889
description: editor.getDescription(verbosity),
890890
title: withNullAsUndefined(editor.getTitle(Verbosity.LONG)),
891-
ariaLabel: editor.isReadonly() ? localize('readonlyEditor', "{0} readonly", editor.getTitle(Verbosity.SHORT)) : editor.getTitle(Verbosity.SHORT)
891+
ariaLabel: computeEditorAriaLabel(editor, this.group, this.editorGroupService.count)
892892
}));
893893

894894
// Shorten labels as needed

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditorPan
215215
return options;
216216
}
217217

218-
protected getAriaLabel(): string {
219-
let ariaLabel: string;
220-
221-
const inputName = this.input?.getName();
222-
if (this.input?.isReadonly()) {
223-
ariaLabel = inputName ? nls.localize('readonlyEditorWithInputAriaLabel', "{0} readonly compare", inputName) : nls.localize('readonlyEditorAriaLabel', "Readonly compare");
224-
} else {
225-
ariaLabel = inputName ? nls.localize('editableEditorWithInputAriaLabel', "{0} compare", inputName) : nls.localize('editableEditorAriaLabel', "Compare");
226-
}
227-
228-
return ariaLabel;
229-
}
230-
231218
private isFileBinaryError(error: Error[]): boolean;
232219
private isFileBinaryError(error: Error): boolean;
233220
private isFileBinaryError(error: Error | Error[]): boolean {

src/vs/workbench/browser/parts/editor/textEditor.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { isCodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser';
2323
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
2424
import { CancellationToken } from 'vs/base/common/cancellation';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
26+
import { computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor';
2627

2728
export interface IEditorConfiguration {
2829
editor: object;
@@ -102,16 +103,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa
102103
}
103104

104105
private computeAriaLabel(): string {
105-
let ariaLabel = this.getAriaLabel();
106-
107-
// Apply group information to help identify in
108-
// which group we are (only if more than one group
109-
// is actually opened)
110-
if (ariaLabel && this.group && this.editorGroupService.count > 1) {
111-
ariaLabel = localize('editorLabelWithGroup', "{0}, {1}", ariaLabel, this.group.ariaLabel);
112-
}
113-
114-
return ariaLabel;
106+
return this._input ? computeEditorAriaLabel(this._input, this.group, this.editorGroupService.count) : localize('editor', "Editor");
115107
}
116108

117109
protected getConfigurationOverrides(): IEditorOptions {
@@ -303,8 +295,6 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa
303295
return undefined;
304296
}
305297

306-
protected abstract getAriaLabel(): string;
307-
308298
dispose(): void {
309299
this.lastAppliedEditorOptions = undefined;
310300

src/vs/workbench/browser/parts/editor/textResourceEditor.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { IModelService } from 'vs/editor/common/services/modelService';
2525
import { IModeService } from 'vs/editor/common/services/modeService';
2626
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
2727
import { EditorOption, IEditorOptions } from 'vs/editor/common/config/editorOptions';
28-
import { basenameOrAuthority } from 'vs/base/common/resources';
2928
import { ModelConstants } from 'vs/editor/common/model';
3029

3130
/**
@@ -108,11 +107,6 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
108107
}
109108
}
110109

111-
protected getAriaLabel(): string {
112-
const inputName = this.input instanceof UntitledTextEditorInput ? basenameOrAuthority(this.input.resource) : this.input?.getName() || nls.localize('writeableEditorAriaLabel', "Editor");
113-
return this.input?.isReadonly() ? nls.localize('readonlyEditor', "{0} readonly", inputName) : inputName;
114-
}
115-
116110
/**
117111
* Reveals the last line of this editor if it has a model set.
118112
*/

src/vs/workbench/common/editor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ export interface IEditorInput extends IDisposable {
383383
*/
384384
readonly resource: URI | undefined;
385385

386+
ariaLabel: string;
387+
386388
/**
387389
* Unique type identifier for this inpput.
388390
*/
@@ -512,6 +514,10 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
512514
return this.getName();
513515
}
514516

517+
get ariaLabel(): string {
518+
return this.getTitle(Verbosity.SHORT);
519+
}
520+
515521
/**
516522
* Returns the preferred editor for this input. A list of candidate editors is passed in that whee registered
517523
* for the input. This allows subclasses to decide late which editor to use for the input on a case by case basis.

src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Action } from 'vs/base/common/actions';
1212
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID, IExplorerService } from 'vs/workbench/contrib/files/common/files';
1313
import { ITextFileService, TextFileOperationError, TextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles';
1414
import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
15-
import { EditorOptions, TextEditorOptions, IEditorCloseEvent, Verbosity } from 'vs/workbench/common/editor';
15+
import { EditorOptions, TextEditorOptions, IEditorCloseEvent } from 'vs/workbench/common/editor';
1616
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
1717
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
1818
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
@@ -245,11 +245,6 @@ export class TextFileEditor extends BaseTextEditor {
245245
}
246246
}
247247

248-
protected getAriaLabel(): string {
249-
const title = this.input?.getTitle(Verbosity.SHORT) || nls.localize('fileEditorAriaLabel', "editor");
250-
return this.input?.isReadonly() ? nls.localize('readonlyEditor', "{0} readonly", title) : title;
251-
}
252-
253248
clearInput(): void {
254249

255250
// Update/clear editor view state in settings

src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1212
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1313
import { IFileService } from 'vs/platform/files/common/files';
1414
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
15+
import { basenameOrAuthority } from 'vs/base/common/resources';
1516

1617
/**
1718
* An editor input to be used for untitled text buffers.
@@ -50,6 +51,10 @@ export class UntitledTextEditorInput extends TextResourceEditorInput implements
5051
return UntitledTextEditorInput.ID;
5152
}
5253

54+
get ariaLabel(): string {
55+
return basenameOrAuthority(this.resource);
56+
}
57+
5358
getName(): string {
5459
return this.model.name;
5560
}

0 commit comments

Comments
 (0)