未验证 提交 0483997d 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #98236 from microsoft/isidorn/editor-aria-preview

editor: conoslidte computing of editor aria labels 
......@@ -14,6 +14,7 @@ import { ISerializableView } from 'vs/base/browser/ui/grid/grid';
import { getCodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorService, IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
import { localize } from 'vs/nls';
export const EDITOR_TITLE_HEIGHT = 35;
......@@ -41,6 +42,24 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
splitSizing: 'distribute'
};
export function computeEditorAriaLabel(input: IEditorInput, group: IEditorGroup | undefined, groupCount: number): string {
let ariaLabel = input.getAriaLabel();
if (group && !group.isPinned(input)) {
ariaLabel = `${ariaLabel}, ${localize('preview', "preview")}`;
}
if (group && group.isSticky(input)) {
ariaLabel = `${ariaLabel}, ${localize('pinned', "pinned")}`;
}
// Apply group information to help identify in
// which group we are (only if more than one group
// is actually opened)
if (group && groupCount > 1) {
ariaLabel = `${ariaLabel}, ${group.ariaLabel}`;
}
return ariaLabel;
}
export function impactsEditorPartOptions(event: IConfigurationChangeEvent): boolean {
return event.affectsConfiguration('workbench.editor') || event.affectsConfiguration('workbench.iconTheme');
}
......
......@@ -31,10 +31,10 @@ import { ResourcesDropHandler, DraggedEditorIdentifier, DraggedEditorGroupIdenti
import { Color } from 'vs/base/common/color';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { MergeGroupMode, IMergeGroupOptions, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
import { MergeGroupMode, IMergeGroupOptions, GroupsArrangement, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { addClass, addDisposableListener, hasClass, EventType, EventHelper, removeClass, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode } from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl, EDITOR_TITLE_HEIGHT } from 'vs/workbench/browser/parts/editor/editor';
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl, EDITOR_TITLE_HEIGHT, computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor';
import { CloseOneEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { BreadcrumbsControl } from 'vs/workbench/browser/parts/editor/breadcrumbsControl';
......@@ -102,7 +102,8 @@ export class TabsTitleControl extends TitleControl {
@IConfigurationService configurationService: IConfigurationService,
@IFileService fileService: IFileService,
@IEditorService private readonly editorService: EditorServiceImpl,
@IPathService private readonly pathService: IPathService
@IPathService private readonly pathService: IPathService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService
) {
super(parent, accessor, group, contextMenuService, instantiationService, contextKeyService, keybindingService, telemetryService, notificationService, menuService, quickInputService, themeService, extensionService, configurationService, fileService);
......@@ -881,14 +882,13 @@ export class TabsTitleControl extends TitleControl {
private computeTabLabels(): void {
const { labelFormat } = this.accessor.partOptions;
const { verbosity, shortenDuplicates } = this.getLabelConfigFlags(labelFormat);
// Build labels and descriptions for each editor
const labels = this.group.editors.map(editor => ({
editor,
name: editor.getName(),
description: editor.getDescription(verbosity),
title: withNullAsUndefined(editor.getTitle(Verbosity.LONG)),
ariaLabel: editor.isReadonly() ? localize('readonlyEditor', "{0} readonly", editor.getTitle(Verbosity.SHORT)) : editor.getTitle(Verbosity.SHORT)
ariaLabel: computeEditorAriaLabel(editor, this.group, this.editorGroupService.count)
}));
// Shorten labels as needed
......
......@@ -215,19 +215,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditorPan
return options;
}
protected getAriaLabel(): string {
let ariaLabel: string;
const inputName = this.input?.getName();
if (this.input?.isReadonly()) {
ariaLabel = inputName ? nls.localize('readonlyEditorWithInputAriaLabel', "{0} readonly compare", inputName) : nls.localize('readonlyEditorAriaLabel', "Readonly compare");
} else {
ariaLabel = inputName ? nls.localize('editableEditorWithInputAriaLabel', "{0} compare", inputName) : nls.localize('editableEditorAriaLabel', "Compare");
}
return ariaLabel;
}
private isFileBinaryError(error: Error[]): boolean;
private isFileBinaryError(error: Error): boolean;
private isFileBinaryError(error: Error | Error[]): boolean {
......
......@@ -23,6 +23,7 @@ import { isCodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { computeEditorAriaLabel } from 'vs/workbench/browser/parts/editor/editor';
export interface IEditorConfiguration {
editor: object;
......@@ -102,16 +103,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa
}
private computeAriaLabel(): string {
let ariaLabel = this.getAriaLabel();
// Apply group information to help identify in
// which group we are (only if more than one group
// is actually opened)
if (ariaLabel && this.group && this.editorGroupService.count > 1) {
ariaLabel = localize('editorLabelWithGroup', "{0}, {1}", ariaLabel, this.group.ariaLabel);
}
return ariaLabel;
return this._input ? computeEditorAriaLabel(this._input, this.group, this.editorGroupService.count) : localize('editor', "Editor");
}
protected getConfigurationOverrides(): IEditorOptions {
......@@ -303,8 +295,6 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditorPa
return undefined;
}
protected abstract getAriaLabel(): string;
dispose(): void {
this.lastAppliedEditorOptions = undefined;
......
......@@ -25,7 +25,6 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { EditorOption, IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { basenameOrAuthority } from 'vs/base/common/resources';
import { ModelConstants } from 'vs/editor/common/model';
/**
......@@ -108,11 +107,6 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
}
}
protected getAriaLabel(): string {
const inputName = this.input instanceof UntitledTextEditorInput ? basenameOrAuthority(this.input.resource) : this.input?.getName() || nls.localize('writeableEditorAriaLabel', "Editor");
return this.input?.isReadonly() ? nls.localize('readonlyEditor', "{0} readonly", inputName) : inputName;
}
/**
* Reveals the last line of this editor if it has a model set.
*/
......
......@@ -403,6 +403,11 @@ export interface IEditorInput extends IDisposable {
*/
getTitle(verbosity?: Verbosity): string | undefined;
/**
* Returns the aria label to be read out by a screen reader.
*/
getAriaLabel(): string;
/**
* Resolves the input.
*/
......@@ -512,6 +517,10 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
return this.getName();
}
getAriaLabel(): string {
return this.getTitle(Verbosity.SHORT);
}
/**
* Returns the preferred editor for this input. A list of candidate editors is passed in that whee registered
* for the input. This allows subclasses to decide late which editor to use for the input on a case by case basis.
......
......@@ -12,7 +12,7 @@ import { Action } from 'vs/base/common/actions';
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID, IExplorerService } from 'vs/workbench/contrib/files/common/files';
import { ITextFileService, TextFileOperationError, TextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles';
import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
import { EditorOptions, TextEditorOptions, IEditorCloseEvent, Verbosity } from 'vs/workbench/common/editor';
import { EditorOptions, TextEditorOptions, IEditorCloseEvent } from 'vs/workbench/common/editor';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
......@@ -245,11 +245,6 @@ export class TextFileEditor extends BaseTextEditor {
}
}
protected getAriaLabel(): string {
const title = this.input?.getTitle(Verbosity.SHORT) || nls.localize('fileEditorAriaLabel', "editor");
return this.input?.isReadonly() ? nls.localize('readonlyEditor', "{0} readonly", title) : title;
}
clearInput(): void {
// Update/clear editor view state in settings
......
......@@ -12,6 +12,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IFileService } from 'vs/platform/files/common/files';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { basenameOrAuthority } from 'vs/base/common/resources';
/**
* An editor input to be used for untitled text buffers.
......@@ -50,6 +51,10 @@ export class UntitledTextEditorInput extends TextResourceEditorInput implements
return UntitledTextEditorInput.ID;
}
get ariaLabel(): string {
return basenameOrAuthority(this.resource);
}
getName(): string {
return this.model.name;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册