提交 05f7db06 编写于 作者: A Alex Dima

Fixes #27216: Change editor selection when a valid `selectionchange` event comes in.

上级 f329f2ba
......@@ -168,6 +168,10 @@ export class TextAreaHandler extends ViewPart {
}
return PagedScreenReaderStrategy.fromEditorSelection(currentState, simpleModel, this._selections[0]);
},
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
return this._context.model.deduceModelPositionRelativeToViewPosition(viewAnchorPosition, deltaOffset, lineFeedCnt);
}
};
......@@ -201,6 +205,10 @@ export class TextAreaHandler extends ViewPart {
}
}));
this._register(this._textAreaInput.onSelectionChangeRequest((modelSelection: Selection) => {
this._viewController.setSelection('keyboard', modelSelection);
}));
this._register(this._textAreaInput.onCompositionStart(() => {
const lineNumber = this._selections[0].startLineNumber;
const column = this._selections[0].startColumn;
......
......@@ -5,6 +5,8 @@
'use strict';
import { RunOnceScheduler } from 'vs/base/common/async';
import { Position } from 'vs/editor/common/core/position';
import { Selection } from 'vs/editor/common/core/selection';
import * as strings from 'vs/base/common/strings';
import Event, { Emitter } from 'vs/base/common/event';
import { KeyCode } from 'vs/base/common/keyCodes';
......@@ -37,7 +39,7 @@ export interface ITextAreaInputHost {
getPlainTextToCopy(): string;
getHTMLToCopy(): string;
getScreenReaderContent(currentState: TextAreaState): TextAreaState;
// deduceEditorPosition(anchor: Position, delta: number, lineFeedCnt: number): Position;
deduceModelPosition(viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position;
}
/**
......@@ -80,6 +82,9 @@ export class TextAreaInput extends Disposable {
private _onCompositionEnd = this._register(new Emitter<void>());
public onCompositionEnd: Event<void> = this._onCompositionEnd.event;
private _onSelectionChangeRequest = this._register(new Emitter<Selection>());
public onSelectionChangeRequest: Event<Selection> = this._onSelectionChangeRequest.event;
// ---
private readonly _host: ITextAreaInputHost;
......@@ -363,16 +368,18 @@ export class TextAreaInput extends Disposable {
return;
}
// const newSelectionStartPosition = this._textAreaState.deduceEditorPosition(newSelectionStart);
// const newSelectionEndPosition = this._textAreaState.deduceEditorPosition(newSelectionEnd);
const _newSelectionStartPosition = this._textAreaState.deduceEditorPosition(newSelectionStart);
const newSelectionStartPosition = this._host.deduceModelPosition(_newSelectionStartPosition[0], _newSelectionStartPosition[1], _newSelectionStartPosition[2]);
const _newSelectionEndPosition = this._textAreaState.deduceEditorPosition(newSelectionEnd);
const newSelectionEndPosition = this._host.deduceModelPosition(_newSelectionEndPosition[0], _newSelectionEndPosition[1], _newSelectionEndPosition[2]);
const newSelection = new Selection(
newSelectionStartPosition.lineNumber, newSelectionStartPosition.column,
newSelectionEndPosition.lineNumber, newSelectionEndPosition.column
);
// // TODO: React here to the new text area selection
// console.warn('!!!!!!!' + Date.now() + ':: RECEIVED selectionchange');
// console.log(this._textArea.getSelectionStart(), this._textArea.getSelectionEnd());
// console.log(this._textAreaState.selectionStart, this._textAreaState.selectionEnd);
// console.log(this._textAreaState.selectionStartPosition, this._textAreaState.selectionEndPosition);
// console.log(newSelectionStartPosition);
// console.log(newSelectionEndPosition);
this._onSelectionChangeRequest.fire(newSelection);
}));
}
......
......@@ -6,6 +6,7 @@
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { Position } from 'vs/editor/common/core/position';
import { Selection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { ICommandService } from 'vs/platform/commands/common/commands';
......@@ -93,6 +94,13 @@ export class ViewController {
this.commandService.executeCommand(editorCommon.Handler.Cut, {});
}
public setSelection(source: string, modelSelection: Selection): void {
this._execCoreEditorCommandFunc(CoreNavigationCommands.SetSelection, {
source: source,
selection: modelSelection
});
}
private _validateViewColumn(viewPosition: Position): Position {
let minColumn = this.viewModel.getLineMinColumn(viewPosition.lineNumber);
if (viewPosition.column < minColumn) {
......
......@@ -1507,6 +1507,26 @@ export namespace CoreNavigationCommands {
);
}
});
export const SetSelection: CoreEditorCommand = registerEditorCommand(new class extends CoreEditorCommand {
constructor() {
super({
id: 'setSelection',
precondition: null
});
}
public runCoreEditorCommand(cursors: ICursors, args: any): void {
cursors.context.model.pushStackElement();
cursors.setStates(
args.source,
CursorChangeReason.Explicit,
[
CursorState.fromModelSelection(args.selection)
]
);
}
});
}
export namespace CoreEditingCommands {
......
......@@ -137,6 +137,7 @@ export interface IViewModel {
getModelLineMaxColumn(modelLineNumber: number): number;
validateModelPosition(modelPosition: IPosition): Position;
deduceModelPositionRelativeToViewPosition(viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position;
getPlainTextToCopy(ranges: Range[], emptySelectionClipboard: boolean): string;
getHTMLToCopy(ranges: Range[], emptySelectionClipboard: boolean): string;
}
......
......@@ -440,6 +440,22 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
return this.model.validatePosition(position);
}
public deduceModelPositionRelativeToViewPosition(viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position {
const modelAnchor = this.coordinatesConverter.convertViewPositionToModelPosition(viewAnchorPosition);
if (this.model.getEOL().length === 2) {
// This model uses CRLF, so the delta must take that into account
if (deltaOffset < 0) {
deltaOffset -= lineFeedCnt;
} else {
deltaOffset += lineFeedCnt;
}
}
const modelAnchorOffset = this.model.getOffsetAt(modelAnchor);
const resultOffset = modelAnchorOffset + deltaOffset;
return this.model.getPositionAt(resultOffset);
}
public getPlainTextToCopy(ranges: Range[], emptySelectionClipboard: boolean): string {
let newLineCharacter = this.model.getEOL();
......
......@@ -7,6 +7,7 @@
import { TextAreaInput, ITextAreaInputHost } from 'vs/editor/browser/controller/textAreaInput';
import { ISimpleModel, TextAreaState, PagedScreenReaderStrategy } from 'vs/editor/browser/controller/textAreaState';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { createFastDomNode } from 'vs/base/browser/fastDomNode';
import * as browser from 'vs/base/browser/browser';
......@@ -100,6 +101,9 @@ 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);
},
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
return null;
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册