未验证 提交 434bc801 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #85822 from microsoft/isidorn/linesPerPage

editor.accessibilityLinesPerPage
......@@ -62,6 +62,7 @@ export class TextAreaHandler extends ViewPart {
private _scrollTop: number;
private _accessibilitySupport: AccessibilitySupport;
private _accessibilityPageSize: number;
private _contentLeft: number;
private _contentWidth: number;
private _contentHeight: number;
......@@ -92,6 +93,7 @@ export class TextAreaHandler extends ViewPart {
const layoutInfo = options.get(EditorOption.layoutInfo);
this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
this._accessibilityPageSize = options.get(EditorOption.accessibilityPageSize);
this._contentLeft = layoutInfo.contentLeft;
this._contentWidth = layoutInfo.contentWidth;
this._contentHeight = layoutInfo.contentHeight;
......@@ -189,7 +191,7 @@ export class TextAreaHandler extends ViewPart {
return TextAreaState.EMPTY;
}
return PagedScreenReaderStrategy.fromEditorSelection(currentState, simpleModel, this._selections[0], this._accessibilitySupport === AccessibilitySupport.Unknown);
return PagedScreenReaderStrategy.fromEditorSelection(currentState, simpleModel, this._selections[0], this._accessibilityPageSize, this._accessibilitySupport === AccessibilitySupport.Unknown);
},
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
......@@ -341,6 +343,7 @@ export class TextAreaHandler extends ViewPart {
const layoutInfo = options.get(EditorOption.layoutInfo);
this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
this._accessibilityPageSize = options.get(EditorOption.accessibilityPageSize);
this._contentLeft = layoutInfo.contentLeft;
this._contentWidth = layoutInfo.contentWidth;
this._contentHeight = layoutInfo.contentHeight;
......
......@@ -226,26 +226,24 @@ export class TextAreaState {
}
export class PagedScreenReaderStrategy {
private static readonly _LINES_PER_PAGE = 10;
private static _getPageOfLine(lineNumber: number): number {
return Math.floor((lineNumber - 1) / PagedScreenReaderStrategy._LINES_PER_PAGE);
private static _getPageOfLine(lineNumber: number, linesPerPage: number): number {
return Math.floor((lineNumber - 1) / linesPerPage);
}
private static _getRangeForPage(page: number): Range {
const offset = page * PagedScreenReaderStrategy._LINES_PER_PAGE;
private static _getRangeForPage(page: number, linesPerPage: number): Range {
const offset = page * linesPerPage;
const startLineNumber = offset + 1;
const endLineNumber = offset + PagedScreenReaderStrategy._LINES_PER_PAGE;
const endLineNumber = offset + linesPerPage;
return new Range(startLineNumber, 1, endLineNumber + 1, 1);
}
public static fromEditorSelection(previousState: TextAreaState, model: ISimpleModel, selection: Range, trimLongText: boolean): TextAreaState {
public static fromEditorSelection(previousState: TextAreaState, model: ISimpleModel, selection: Range, linesPerPage: number, trimLongText: boolean): TextAreaState {
const selectionStartPage = PagedScreenReaderStrategy._getPageOfLine(selection.startLineNumber);
const selectionStartPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionStartPage);
const selectionStartPage = PagedScreenReaderStrategy._getPageOfLine(selection.startLineNumber, linesPerPage);
const selectionStartPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionStartPage, linesPerPage);
const selectionEndPage = PagedScreenReaderStrategy._getPageOfLine(selection.endLineNumber);
const selectionEndPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionEndPage);
const selectionEndPage = PagedScreenReaderStrategy._getPageOfLine(selection.endLineNumber, linesPerPage);
const selectionEndPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionEndPage, linesPerPage);
const pretextRange = selectionStartPageRange.intersectRanges(new Range(1, 1, selection.startLineNumber, selection.startColumn))!;
let pretext = model.getValueInRange(pretextRange, EndOfLinePreference.LF);
......
......@@ -331,6 +331,10 @@ export interface IEditorOptions {
* Defaults to 'auto'. It is best to leave this to 'auto'.
*/
accessibilitySupport?: 'auto' | 'off' | 'on';
/**
* Controls the number of lines in the editor that can be read out by a screen reader
*/
accessibilityPageSize?: number;
/**
* Suggest options.
*/
......@@ -3001,6 +3005,7 @@ export const enum EditorOption {
acceptSuggestionOnCommitCharacter,
acceptSuggestionOnEnter,
accessibilitySupport,
accessibilityPageSize,
ariaLabel,
autoClosingBrackets,
autoClosingOvertype,
......@@ -3128,6 +3133,8 @@ export const EditorOptions = {
}
)),
accessibilitySupport: register(new EditorAccessibilitySupport()),
accessibilityPageSize: register(new EditorIntOption(EditorOption.accessibilityPageSize, 'accessibilityPageSize', 10, 1, Constants.MAX_SAFE_SMALL_INTEGER,
{ description: nls.localize('accessibilityPageSize', "Controls the number of lines in the editor that can be read out by a screen reader. Warning: this has a performance implication for numbers larger than the default.") })),
ariaLabel: register(new EditorStringOption(
EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content")
)),
......
......@@ -103,7 +103,7 @@ function doCreateTest(description: string, inputStr: string, expectedStr: string
const selection = new Range(1, 1 + cursorOffset, 1, 1 + cursorOffset + cursorLength);
return PagedScreenReaderStrategy.fromEditorSelection(currentState, model, selection, true);
return PagedScreenReaderStrategy.fromEditorSelection(currentState, model, selection, 10, true);
},
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
return null!;
......
......@@ -535,7 +535,7 @@ suite('TextAreaState', () => {
function testPagedScreenReaderStrategy(lines: string[], selection: Selection, expected: TextAreaState): void {
const model = TextModel.createFromString(lines.join('\n'));
const actual = PagedScreenReaderStrategy.fromEditorSelection(TextAreaState.EMPTY, model, selection, true);
const actual = PagedScreenReaderStrategy.fromEditorSelection(TextAreaState.EMPTY, model, selection, 10, true);
assert.ok(equalsTextAreaState(actual, expected));
model.dispose();
}
......
......@@ -2730,6 +2730,10 @@ declare namespace monaco.editor {
* Defaults to 'auto'. It is best to leave this to 'auto'.
*/
accessibilitySupport?: 'auto' | 'off' | 'on';
/**
* Controls the number of lines in the editor that can be read out by a screen reader
*/
accessibilityPageSize?: number;
/**
* Suggest options.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册