Не подтверждена Коммит 4849dcc8 создал по автору Johannes Rieken's avatar Johannes Rieken Зафиксировано автором GitHub
Просмотр файлов

Merge branch 'main' into joh/aggregate-amphibian

владельцы 07d716a9 71b2684d
Branches недоступно
Не найдено связанных запросов на слияние
Отображение с 38 дополнений и 112 удаления
+38 -112
......@@ -21,7 +21,7 @@ import { RestrictedRenderingContext, RenderingContext } from '../../../view/rend
import { ViewController } from '../../../view/viewController.js';
import { ClipboardStoredMetadata, getDataToCopy, InMemoryClipboardMetadataManager } from '../clipboardUtils.js';
import { AbstractEditContext } from '../editContextUtils.js';
import { EditContextWrapper, FocusTracker } from './nativeEditContextUtils.js';
import { editContextAddDisposableListener, FocusTracker, ITypeData } from './nativeEditContextUtils.js';
import { ScreenReaderSupport } from './screenReaderSupport.js';
import { Range } from '../../../../common/core/range.js';
import { Selection } from '../../../../common/core/selection.js';
......@@ -30,7 +30,7 @@ import { Position } from '../../../../common/core/position.js';
export class NativeEditContext extends AbstractEditContext {
public readonly domNode: FastDomNode<HTMLDivElement>;
private readonly _editContext: EditContextWrapper;
private readonly _editContext: EditContext;
private readonly _screenReaderSupport: ScreenReaderSupport;
// Overflow guard container
......@@ -39,6 +39,9 @@ export class NativeEditContext extends AbstractEditContext {
private _renderingContext: RenderingContext | undefined;
private _primarySelection: Selection = new Selection(1, 1, 1, 1);
private _textStartPositionWithinEditor: Position = new Position(1, 1);
private _compositionRangeWithinEditor: Range | undefined;
private readonly _focusTracker: FocusTracker;
constructor(
......@@ -55,9 +58,8 @@ export class NativeEditContext extends AbstractEditContext {
this._focusTracker = this._register(new FocusTracker(this.domNode.domNode, (newFocusValue: boolean) => this._context.viewModel.setHasFocus(newFocusValue)));
const editContext = new EditContext();
this.domNode.domNode.editContext = editContext;
this._editContext = new EditContextWrapper(editContext);
this._editContext = new EditContext();
this.domNode.domNode.editContext = this._editContext;
this._screenReaderSupport = instantiationService.createInstance(ScreenReaderSupport, this.domNode, context);
......@@ -87,30 +89,33 @@ export class NativeEditContext extends AbstractEditContext {
}));
// Edit context events
this._register(this._editContext.onTextFormatUpdate(e => this._handleTextFormatUpdate(e)));
this._register(this._editContext.onCharacterBoundsUpdate(e => this._updateCharacterBounds()));
this._register(this._editContext.onTextUpdate(e => {
const compositionRangeWithinEditor = this._editContext.compositionRangeWithinEditor;
this._register(editContextAddDisposableListener(this._editContext, 'textformatupdate', (e) => this._handleTextFormatUpdate(e)));
this._register(editContextAddDisposableListener(this._editContext, 'characterboundsupdate', (e) => this._updateCharacterBounds()));
this._register(editContextAddDisposableListener(this._editContext, 'textupdate', (e) => {
const compositionRangeWithinEditor = this._compositionRangeWithinEditor;
if (compositionRangeWithinEditor) {
const position = this._context.viewModel.getPrimaryCursorState().viewState.position;
const newCompositionRangeWithinEditor = Range.fromPositions(compositionRangeWithinEditor.getStartPosition(), position);
this._editContext.updateCompositionRangeWithinEditor(newCompositionRangeWithinEditor);
this._compositionRangeWithinEditor = newCompositionRangeWithinEditor;
}
this._emitTypeEvent(viewController, e);
// this._screenReaderSupport.writeScreenReaderContent();
// TODO @aiday-mar calling write screen reader content so that the document selection is immediately set
// remove the following when electron will be upgraded
this._screenReaderSupport.writeScreenReaderContent();
}));
this._register(this._editContext.onCompositionStart(e => {
this._register(editContextAddDisposableListener(this._editContext, 'compositionstart', (e) => {
const position = this._context.viewModel.getPrimaryCursorState().viewState.position;
const newCompositionRange = Range.fromPositions(position, position);
this._editContext.updateCompositionRangeWithinEditor(newCompositionRange);
this._compositionRangeWithinEditor = newCompositionRange;
// Utlimately fires onDidCompositionStart() on the editor to notify for example suggest model of composition state
// Updates the composition state of the cursor controller which determines behavior of typing with interceptors
viewController.compositionStart();
// Emits ViewCompositionStartEvent which can be depended on by ViewEventHandlers
this._context.viewModel.onCompositionStart();
}));
this._register(this._editContext.onCompositionEnd(e => {
this._editContext.updateCompositionRangeWithinEditor(undefined);
this._register(editContextAddDisposableListener(this._editContext, 'compositionend', (e) => {
this._compositionRangeWithinEditor = undefined;
// Utlimately fires compositionEnd() on the editor to notify for example suggest model of composition state
// Updates the composition state of the cursor controller which determines behavior of typing with interceptors
viewController.compositionEnd();
......@@ -186,7 +191,7 @@ export class NativeEditContext extends AbstractEditContext {
const editContextState = this._getNewEditContextState();
this._editContext.updateText(0, Number.MAX_SAFE_INTEGER, editContextState.text);
this._editContext.updateSelection(editContextState.selectionStartOffset, editContextState.selectionEndOffset);
this._editContext.updateTextStartPositionWithinEditor(editContextState.textStartPositionWithinEditor);
this._textStartPositionWithinEditor = editContextState.textStartPositionWithinEditor;
}
private _emitTypeEvent(viewController: ViewController, e: TextUpdateEvent): void {
......@@ -194,7 +199,7 @@ export class NativeEditContext extends AbstractEditContext {
return;
}
const model = this._context.viewModel.model;
const offsetOfStartOfText = model.getOffsetAt(this._editContext.textStartPositionWithinEditor);
const offsetOfStartOfText = model.getOffsetAt(this._textStartPositionWithinEditor);
const offsetOfSelectionEnd = model.getOffsetAt(this._primarySelection.getEndPosition());
const offsetOfSelectionStart = model.getOffsetAt(this._primarySelection.getStartPosition());
const selectionEndOffset = offsetOfSelectionEnd - offsetOfStartOfText;
......@@ -277,7 +282,7 @@ export class NativeEditContext extends AbstractEditContext {
return;
}
const formats = e.getTextFormats();
const textStartPositionWithinEditor = this._editContext.textStartPositionWithinEditor;
const textStartPositionWithinEditor = this._textStartPositionWithinEditor;
const decorations: IModelDeltaDecoration[] = [];
formats.forEach(f => {
const textModel = this._context.viewModel.model;
......@@ -336,14 +341,14 @@ export class NativeEditContext extends AbstractEditContext {
}
private _updateCharacterBounds() {
if (!this._parent || !this._editContext.compositionRangeWithinEditor) {
if (!this._parent || !this._compositionRangeWithinEditor) {
return;
}
const options = this._context.configuration.options;
const lineHeight = options.get(EditorOption.lineHeight);
const contentLeft = options.get(EditorOption.layoutInfo).contentLeft;
const parentBounds = this._parent.getBoundingClientRect();
const compositionRangeWithinEditor = this._editContext.compositionRangeWithinEditor;
const compositionRangeWithinEditor = this._compositionRangeWithinEditor;
const verticalOffsetStartOfComposition = this._context.viewLayout.getVerticalOffsetForLineNumber(compositionRangeWithinEditor.startLineNumber);
const editorScrollTop = this._context.viewLayout.getCurrentScrollTop();
const top = parentBounds.top + verticalOffsetStartOfComposition - editorScrollTop;
......@@ -358,7 +363,7 @@ export class NativeEditContext extends AbstractEditContext {
}
}
const textModel = this._context.viewModel.model;
const offsetOfEditContextStart = textModel.getOffsetAt(this._editContext.textStartPositionWithinEditor);
const offsetOfEditContextStart = textModel.getOffsetAt(this._textStartPositionWithinEditor);
const offsetOfCompositionStart = textModel.getOffsetAt(compositionRangeWithinEditor.getStartPosition());
const offsetOfCompositionStartInEditContext = offsetOfCompositionStart - offsetOfEditContextStart;
this._editContext.updateCharacterBounds(offsetOfCompositionStartInEditContext, characterBounds);
......@@ -385,10 +390,3 @@ export class NativeEditContext extends AbstractEditContext {
clipboardService.writeText(dataToCopy.text);
}
}
interface ITypeData {
text: string;
replacePrevCharCnt: number;
replaceNextCharCnt: number;
positionDelta: number;
}
......@@ -5,87 +5,12 @@
import { addDisposableListener } from '../../../../../base/browser/dom.js';
import { IDisposable, Disposable } from '../../../../../base/common/lifecycle.js';
import { Position } from '../../../../common/core/position.js';
import { Range } from '../../../../common/core/range.js';
export class EditContextWrapper {
private _textStartPositionWithinEditor: Position = new Position(1, 1);
private _compositionRangeWithinEditor: Range | undefined;
constructor(private readonly _editContext: EditContext) { }
onTextUpdate(listener: (this: GlobalEventHandlers, ev: TextUpdateEvent) => void) {
return editContextAddDisposableListener(this._editContext, 'textupdate', listener);
}
onCompositionStart(listener: (this: GlobalEventHandlers, ev: Event) => void) {
return editContextAddDisposableListener(this._editContext, 'compositionstart', listener);
}
onCompositionEnd(listener: (this: GlobalEventHandlers, ev: Event) => void) {
return editContextAddDisposableListener(this._editContext, 'compositionend', listener);
}
onCharacterBoundsUpdate(listener: (this: GlobalEventHandlers, ev: CharacterBoundsUpdateEvent) => void) {
return editContextAddDisposableListener(this._editContext, 'characterboundsupdate', listener);
}
onTextFormatUpdate(listener: (this: GlobalEventHandlers, ev: TextFormatUpdateEvent) => void) {
return editContextAddDisposableListener(this._editContext, 'textformatupdate', listener);
}
updateText(rangeStart: number, rangeEnd: number, text: string): void {
this._editContext.updateText(rangeStart, rangeEnd, text);
}
updateSelection(selectionStart: number, selectionEnd: number): void {
this._editContext.updateSelection(selectionStart, selectionEnd);
}
updateControlBounds(controlBounds: DOMRect): void {
this._editContext.updateControlBounds(controlBounds);
}
updateSelectionBounds(selectionBounds: DOMRect): void {
this._editContext.updateSelectionBounds(selectionBounds);
}
updateCharacterBounds(rangeStart: number, characterBounds: DOMRect[]): void {
this._editContext.updateCharacterBounds(rangeStart, characterBounds);
}
updateTextStartPositionWithinEditor(textStartPositionWithinEditor: Position): void {
this._textStartPositionWithinEditor = textStartPositionWithinEditor;
}
updateCompositionRangeWithinEditor(compositionRange: Range | undefined): void {
this._compositionRangeWithinEditor = compositionRange;
}
public get text(): string {
return this._editContext.text;
}
public get selectionStart(): number {
return this._editContext.selectionStart;
}
public get selectionEnd(): number {
return this._editContext.selectionEnd;
}
public get characterBounds(): DOMRect[] {
return this._editContext.characterBounds();
}
public get textStartPositionWithinEditor(): Position {
return this._textStartPositionWithinEditor;
}
public get compositionRangeWithinEditor(): Range | undefined {
return this._compositionRangeWithinEditor;
}
export interface ITypeData {
text: string;
replacePrevCharCnt: number;
replaceNextCharCnt: number;
positionDelta: number;
}
export class FocusTracker extends Disposable {
......
......@@ -113,9 +113,12 @@ export class ScreenReaderSupport {
private _getScreenReaderContentState(): ScreenReaderContentState | undefined {
// Make the screen reader content always be visible because of the bug and also set the selection
if (this._accessibilitySupport === AccessibilitySupport.Disabled) {
return;
}
// TODO @aiday-mar Ultimately uncomment this code when Electron will be upgraded
// if (this._accessibilitySupport === AccessibilitySupport.Disabled) {
// return;
// }
const accessibilityPageSize = this._accessibilitySupport === AccessibilitySupport.Disabled ? 1 : this._accessibilityPageSize;
const simpleModel: ISimpleModel = {
getLineCount: (): number => {
return this._context.viewModel.getLineCount();
......@@ -133,7 +136,7 @@ export class ScreenReaderSupport {
return this._context.viewModel.modifyPosition(position, offset);
}
};
return PagedScreenReaderStrategy.fromEditorSelection(simpleModel, this._primarySelection, this._accessibilityPageSize, this._accessibilitySupport === AccessibilitySupport.Unknown);
return PagedScreenReaderStrategy.fromEditorSelection(simpleModel, this._primarySelection, accessibilityPageSize, this._accessibilitySupport === AccessibilitySupport.Unknown);
}
private _setSelectionOfScreenReaderContent(selectionOffsetStart: number, selectionOffsetEnd: number): void {
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать