提交 0e8cd85d 编写于 作者: A Alex Dima

Simplifications

上级 972223e5
...@@ -21,26 +21,6 @@ import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations ...@@ -21,26 +21,6 @@ import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations
import { TextModelEventType, ModelRawContentChangedEvent, RawContentChangedType } from 'vs/editor/common/model/textModelEvents'; import { TextModelEventType, ModelRawContentChangedEvent, RawContentChangedType } from 'vs/editor/common/model/textModelEvents';
import { CursorEventType, CursorChangeReason, ICursorPositionChangedEvent, VerticalRevealType, ICursorSelectionChangedEvent, ICursorRevealRangeEvent, CursorScrollRequest } from 'vs/editor/common/controller/cursorEvents'; import { CursorEventType, CursorChangeReason, ICursorPositionChangedEvent, VerticalRevealType, ICursorSelectionChangedEvent, ICursorRevealRangeEvent, CursorScrollRequest } from 'vs/editor/common/controller/cursorEvents';
class CursorOperationArgs<T> {
public readonly eventSource: string;
public readonly eventData: T;
constructor(eventSource: string, eventData: T) {
this.eventSource = eventSource;
this.eventData = eventData;
}
}
interface ICommandData {
operations: editorCommon.IIdentifiedSingleEditOperation[];
hadTrackedEditOperation: boolean;
}
interface ICommandsData {
operations: editorCommon.IIdentifiedSingleEditOperation[];
hadTrackedEditOperation: boolean;
}
export class Cursor extends Disposable implements ICursors { export class Cursor extends Disposable implements ICursors {
public onDidChangePosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable { public onDidChangePosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable {
...@@ -457,8 +437,6 @@ export class Cursor extends Disposable implements ICursors { ...@@ -457,8 +437,6 @@ export class Cursor extends Disposable implements ICursors {
return; return;
} }
const args = new CursorOperationArgs(source, payload);
const oldSelections = this._cursors.getSelections(); const oldSelections = this._cursors.getSelections();
const oldViewSelections = this._cursors.getViewSelections(); const oldViewSelections = this._cursors.getViewSelections();
let cursorChangeReason = CursorChangeReason.NotSet; let cursorChangeReason = CursorChangeReason.NotSet;
...@@ -471,20 +449,20 @@ export class Cursor extends Disposable implements ICursors { ...@@ -471,20 +449,20 @@ export class Cursor extends Disposable implements ICursors {
try { try {
switch (handlerId) { switch (handlerId) {
case H.Type: case H.Type:
this._executeEditOperation(this._type(args)); this._type(source, <string>payload.text);
break; break;
case H.ReplacePreviousChar: case H.ReplacePreviousChar:
this._executeEditOperation(this._replacePreviousChar(args)); this._replacePreviousChar(<string>payload.text, <number>payload.replaceCharCnt);
break; break;
case H.Paste: case H.Paste:
cursorChangeReason = CursorChangeReason.Paste; cursorChangeReason = CursorChangeReason.Paste;
this._executeEditOperation(this._paste(args)); this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine);
break; break;
case H.Cut: case H.Cut:
this._executeEditOperation(this._cut(args)); this._cut();
break; break;
case H.Undo: case H.Undo:
...@@ -498,11 +476,11 @@ export class Cursor extends Disposable implements ICursors { ...@@ -498,11 +476,11 @@ export class Cursor extends Disposable implements ICursors {
break; break;
case H.ExecuteCommand: case H.ExecuteCommand:
this._executeEditOperation(this._externalExecuteCommand(args)); this._externalExecuteCommand(<editorCommon.ICommand>payload);
break; break;
case H.ExecuteCommands: case H.ExecuteCommands:
this._executeEditOperation(this._externalExecuteCommands(args)); this._externalExecuteCommands(<editorCommon.ICommand[]>payload);
break; break;
} }
} catch (err) { } catch (err) {
...@@ -514,18 +492,14 @@ export class Cursor extends Disposable implements ICursors { ...@@ -514,18 +492,14 @@ export class Cursor extends Disposable implements ICursors {
const newSelections = this._cursors.getSelections(); const newSelections = this._cursors.getSelections();
const newViewSelections = this._cursors.getViewSelections(); const newViewSelections = this._cursors.getViewSelections();
if (Cursor._somethingChanged(oldSelections, oldViewSelections, newSelections, newViewSelections)) { if (Cursor._somethingChanged(oldSelections, oldViewSelections, newSelections, newViewSelections)) {
this._emitCursorPositionChanged(args.eventSource, cursorChangeReason); this._emitCursorPositionChanged(source, cursorChangeReason);
this._revealRange(RevealTarget.Primary, VerticalRevealType.Simple, true); this._revealRange(RevealTarget.Primary, VerticalRevealType.Simple, true);
this._emitCursorSelectionChanged(args.eventSource, cursorChangeReason); this._emitCursorSelectionChanged(source, cursorChangeReason);
} }
} }
// -------------------- START editing operations private _type(source: string, text: string): void {
if (!this._isDoingComposition && source === 'keyboard') {
private _type(args: CursorOperationArgs<{ text: string; }>): EditOperationResult {
const text = args.eventData.text;
if (!this._isDoingComposition && args.eventSource === 'keyboard') {
// If this event is coming straight from the keyboard, look for electric characters and enter // If this event is coming straight from the keyboard, look for electric characters and enter
for (let i = 0, len = text.length; i < len; i++) { for (let i = 0, len = text.length; i < len; i++) {
...@@ -542,48 +516,37 @@ export class Cursor extends Disposable implements ICursors { ...@@ -542,48 +516,37 @@ export class Cursor extends Disposable implements ICursors {
this._executeEditOperation(TypeOperations.typeWithInterceptors(this.context.config, this.context.model, this.getSelections(), chr)); this._executeEditOperation(TypeOperations.typeWithInterceptors(this.context.config, this.context.model, this.getSelections(), chr));
} }
return null;
} else { } else {
return TypeOperations.typeWithoutInterceptors(this.context.config, this.context.model, this.getSelections(), text); this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this.context.config, this.context.model, this.getSelections(), text));
} }
} }
private _replacePreviousChar(args: CursorOperationArgs<{ text: string; replaceCharCnt: number; }>): EditOperationResult { private _replacePreviousChar(text: string, replaceCharCnt: number): void {
const text = args.eventData.text; this._executeEditOperation(TypeOperations.replacePreviousChar(this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt));
const replaceCharCnt = args.eventData.replaceCharCnt;
return TypeOperations.replacePreviousChar(this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt);
} }
private _paste(args: CursorOperationArgs<{ pasteOnNewLine: boolean; text: string; }>): EditOperationResult { private _paste(text: string, pasteOnNewLine: boolean): void {
const pasteOnNewLine = args.eventData.pasteOnNewLine; this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), pasteOnNewLine, text));
const text = args.eventData.text;
return TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), pasteOnNewLine, text);
} }
private _cut(args: CursorOperationArgs<void>): EditOperationResult { private _cut(): void {
return DeleteOperations.cut(this.context.config, this.context.model, this.getSelections()); this._executeEditOperation(DeleteOperations.cut(this.context.config, this.context.model, this.getSelections()));
} }
// -------------------- END editing operations private _externalExecuteCommand(command: editorCommon.ICommand): void {
private _externalExecuteCommand(args: CursorOperationArgs<editorCommon.ICommand>): EditOperationResult {
const command = args.eventData;
this._cursors.killSecondaryCursors(); this._cursors.killSecondaryCursors();
return new EditOperationResult([command], { this._executeEditOperation(new EditOperationResult([command], {
shouldPushStackElementBefore: false, shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false shouldPushStackElementAfter: false
}); }));
} }
private _externalExecuteCommands(args: CursorOperationArgs<editorCommon.ICommand[]>): EditOperationResult { private _externalExecuteCommands(commands: editorCommon.ICommand[]): void {
const commands = args.eventData; this._executeEditOperation(new EditOperationResult(commands, {
return new EditOperationResult(commands, {
shouldPushStackElementBefore: false, shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false shouldPushStackElementAfter: false
}); }));
} }
} }
...@@ -594,6 +557,16 @@ interface IExecContext { ...@@ -594,6 +557,16 @@ interface IExecContext {
readonly positionMarkers: string[]; readonly positionMarkers: string[];
} }
interface ICommandData {
operations: editorCommon.IIdentifiedSingleEditOperation[];
hadTrackedEditOperation: boolean;
}
interface ICommandsData {
operations: editorCommon.IIdentifiedSingleEditOperation[];
hadTrackedEditOperation: boolean;
}
class CommandExecutor { class CommandExecutor {
public static executeCommands(model: editorCommon.IModel, selectionsBefore: Selection[], commands: editorCommon.ICommand[]): Selection[] { public static executeCommands(model: editorCommon.IModel, selectionsBefore: Selection[], commands: editorCommon.ICommand[]): Selection[] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册