提交 4183dd9d 编写于 作者: A Alex Dima

More cleanup around editing commands

上级 44c9c09a
......@@ -16,10 +16,12 @@ import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { CursorColumns } from 'vs/editor/common/controller/cursorCommon';
import { CursorColumns, EditOperationResult } from 'vs/editor/common/controller/cursorCommon';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { WordNavigationType } from 'vs/editor/common/controller/cursorWordOperations';
import { WordOperations, WordNavigationType } from 'vs/editor/common/controller/cursorWordOperations';
import { ColumnSelection, IColumnSelectResult } from 'vs/editor/common/controller/cursorColumnSelection';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
export interface ITypingListener {
(): void;
......@@ -1337,18 +1339,6 @@ export class Cursor extends EventEmitter {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.expandLineSelection(oneCursor, oneCtx));
}
private _lineInsertBefore(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.lineInsertBefore(oneCursor, oneCtx));
}
private _lineInsertAfter(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.lineInsertAfter(oneCursor, oneCtx));
}
private _lineBreakInsert(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.lineBreakInsert(oneCursor, oneCtx));
}
private _word(inSelectionMode: boolean, ctx: IMultipleCursorOperationContext): boolean {
this.cursors.killSecondaryCursors();
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.word(oneCursor, inSelectionMode, ctx.eventData.position, oneCtx));
......@@ -1382,6 +1372,41 @@ export class Cursor extends EventEmitter {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.cancelSelection(oneCursor, oneCtx));
}
// -------------------- START editing operations
private _doApplyEdit(cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext, callable: (oneCursor: OneCursor, cursorIndex: number) => EditOperationResult): boolean {
let r = callable(oneCursor, cursorIndex);
if (r) {
oneCtx.executeCommand = r.command;
oneCtx.shouldPushStackElementBefore = r.shouldPushStackElementBefore;
oneCtx.shouldPushStackElementAfter = r.shouldPushStackElementAfter;
oneCtx.isAutoWhitespaceCommand = r.isAutoWhitespaceCommand;
oneCtx.shouldRevealHorizontal = r.shouldRevealHorizontal;
oneCtx.cursorPositionChangeReason = r.cursorPositionChangeReason;
}
return true;
}
private _applyEditForAll(ctx: IMultipleCursorOperationContext, callable: (oneCursor: OneCursor, cursorIndex: number) => EditOperationResult): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => this._doApplyEdit(cursorIndex, oneCursor, oneCtx, callable), false, false);
}
private _applyEditForAllSorted(ctx: IMultipleCursorOperationContext, callable: (oneCursor: OneCursor, cursorIndex: number) => EditOperationResult): boolean {
return this._invokeForAllSorted(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => this._doApplyEdit(cursorIndex, oneCursor, oneCtx, callable), false, false);
}
private _lineInsertBefore(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => TypeOperations.lineInsertBefore(cursor.config, cursor.model, cursor.modelState));
}
private _lineInsertAfter(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => TypeOperations.lineInsertAfter(cursor.config, cursor.model, cursor.modelState));
}
private _lineBreakInsert(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => TypeOperations.lineBreakInsert(cursor.config, cursor.model, cursor.modelState));
}
private _type(ctx: IMultipleCursorOperationContext): boolean {
var text = ctx.eventData.text;
......@@ -1403,7 +1428,7 @@ export class Cursor extends EventEmitter {
// Here we must interpret each typed character individually, that's why we create a new context
ctx.hasExecutedCommands = this._createAndInterpretHandlerCtx(ctx.eventSource, ctx.eventData, (charHandlerCtx: IMultipleCursorOperationContext) => {
this._invokeForAll(charHandlerCtx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.type(oneCursor, chr, oneCtx), false, false);
this._applyEditForAll(charHandlerCtx, (cursor) => TypeOperations.typeWithInterceptors(cursor.config, cursor.model, cursor.modelState, chr));
// The last typed character gets to win
ctx.cursorPositionChangeReason = charHandlerCtx.cursorPositionChangeReason;
......@@ -1414,7 +1439,7 @@ export class Cursor extends EventEmitter {
}
} else {
this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.actualType(oneCursor, text, oneCtx));
this._applyEditForAll(ctx, (cursor) => TypeOperations.typeWithoutInterceptors(cursor.config, cursor.model, cursor.modelState, text));
}
return true;
......@@ -1423,31 +1448,86 @@ export class Cursor extends EventEmitter {
private _replacePreviousChar(ctx: IMultipleCursorOperationContext): boolean {
let text = ctx.eventData.text;
let replaceCharCnt = ctx.eventData.replaceCharCnt;
return this._invokeForAll(ctx, (cursorIndex, oneCursor, oneCtx) => OneCursorOp.replacePreviousChar(oneCursor, text, replaceCharCnt, oneCtx), false, false);
return this._applyEditForAll(ctx, (cursor) => TypeOperations.replacePreviousChar(cursor.config, cursor.model, cursor.modelState, text, replaceCharCnt));
}
private _tab(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.tab(oneCursor, oneCtx), false, false);
return this._applyEditForAll(ctx, (cursor) => TypeOperations.tab(cursor.config, cursor.model, cursor.modelState));
}
private _indent(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.indent(oneCursor, oneCtx));
return this._applyEditForAll(ctx, (cursor) => TypeOperations.indent(cursor.config, cursor.model, cursor.modelState));
}
private _outdent(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.outdent(oneCursor, oneCtx));
return this._applyEditForAll(ctx, (cursor) => TypeOperations.outdent(cursor.config, cursor.model, cursor.modelState));
}
private _distributePasteToCursors(ctx: IMultipleCursorOperationContext): string[] {
if (ctx.eventData.pasteOnNewLine) {
return null;
}
var selections = this.cursors.getSelections();
if (selections.length === 1) {
return null;
}
for (var i = 0; i < selections.length; i++) {
if (selections[i].startLineNumber !== selections[i].endLineNumber) {
return null;
}
}
var pastePieces = ctx.eventData.text.split(/\r\n|\r|\n/);
if (pastePieces.length !== selections.length) {
return null;
}
return pastePieces;
}
private _paste(ctx: IMultipleCursorOperationContext): boolean {
var distributedPaste = this._distributePasteToCursors(ctx);
if (distributedPaste) {
return this._invokeForAllSorted(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.paste(oneCursor, distributedPaste[cursorIndex], false, oneCtx));
return this._applyEditForAllSorted(ctx, (cursor, cursorIndex) => TypeOperations.paste(cursor.config, cursor.model, cursor.modelState, distributedPaste[cursorIndex], false));
} else {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.paste(oneCursor, ctx.eventData.text, ctx.eventData.pasteOnNewLine, oneCtx));
return this._applyEditForAll(ctx, (cursor) => TypeOperations.paste(cursor.config, cursor.model, cursor.modelState, ctx.eventData.text, ctx.eventData.pasteOnNewLine));
}
}
private _deleteLeft(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteLeft(cursor.config, cursor.model, cursor.modelState));
}
private _deleteWordLeft(whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => WordOperations.deleteWordLeft(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType));
}
private _deleteRight(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteRight(cursor.config, cursor.model, cursor.modelState));
}
private _deleteWordRight(whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => WordOperations.deleteWordRight(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType));
}
private _deleteAllLeft(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllLeft(cursor.config, cursor.model, cursor.modelState));
}
private _deleteAllRight(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllRight(cursor.config, cursor.model, cursor.modelState));
}
private _cut(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.cut(cursor.config, cursor.model, cursor.modelState, this.enableEmptySelectionClipboard));
}
// -------------------- END editing operations
private _revealLine(ctx: IMultipleCursorOperationContext): boolean {
const revealLineArg: editorCommon.RevealLineArguments = ctx.eventData;
const lineNumber = revealLineArg.lineNumber + 1;
......@@ -1538,58 +1618,6 @@ export class Cursor extends EventEmitter {
return this._editorScroll(ctx);
}
private _distributePasteToCursors(ctx: IMultipleCursorOperationContext): string[] {
if (ctx.eventData.pasteOnNewLine) {
return null;
}
var selections = this.cursors.getSelections();
if (selections.length === 1) {
return null;
}
for (var i = 0; i < selections.length; i++) {
if (selections[i].startLineNumber !== selections[i].endLineNumber) {
return null;
}
}
var pastePieces = ctx.eventData.text.split(/\r\n|\r|\n/);
if (pastePieces.length !== selections.length) {
return null;
}
return pastePieces;
}
private _deleteLeft(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteLeft(oneCursor, oneCtx), false, false);
}
private _deleteWordLeft(whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteWordLeft(oneCursor, whitespaceHeuristics, wordNavigationType, oneCtx), false, false);
}
private _deleteRight(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteRight(oneCursor, oneCtx), false, false);
}
private _deleteWordRight(whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteWordRight(oneCursor, whitespaceHeuristics, wordNavigationType, oneCtx), false, false);
}
private _deleteAllLeft(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteAllLeft(oneCursor, oneCtx), false, false);
}
private _deleteAllRight(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.deleteAllRight(oneCursor, oneCtx), false, false);
}
private _cut(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.cut(oneCursor, this.enableEmptySelectionClipboard, oneCtx));
}
private _undo(ctx: IMultipleCursorOperationContext): boolean {
ctx.cursorPositionChangeReason = editorCommon.CursorChangeReason.Undo;
ctx.hasExecutedCommands = true;
......
......@@ -86,7 +86,7 @@ export class EditOperationResult {
constructor(
command: ICommand,
opts?: {
opts: {
shouldPushStackElementBefore: boolean;
shouldPushStackElementAfter: boolean;
isAutoWhitespaceCommand?: boolean;
......@@ -95,28 +95,20 @@ export class EditOperationResult {
}
) {
this.command = command;
this.shouldPushStackElementBefore = false;
this.shouldPushStackElementAfter = false;
this.shouldPushStackElementBefore = opts.shouldPushStackElementBefore;
this.shouldPushStackElementAfter = opts.shouldPushStackElementAfter;
this.isAutoWhitespaceCommand = false;
this.shouldRevealHorizontal = true;
this.cursorPositionChangeReason = CursorChangeReason.NotSet;
if (typeof opts !== 'undefined') {
if (typeof opts.shouldPushStackElementBefore !== 'undefined') {
this.shouldPushStackElementBefore = opts.shouldPushStackElementBefore;
}
if (typeof opts.shouldPushStackElementAfter !== 'undefined') {
this.shouldPushStackElementAfter = opts.shouldPushStackElementAfter;
}
if (typeof opts.isAutoWhitespaceCommand !== 'undefined') {
this.isAutoWhitespaceCommand = opts.isAutoWhitespaceCommand;
}
if (typeof opts.shouldRevealHorizontal !== 'undefined') {
this.shouldRevealHorizontal = opts.shouldRevealHorizontal;
}
if (typeof opts.cursorPositionChangeReason !== 'undefined') {
this.cursorPositionChangeReason = opts.cursorPositionChangeReason;
}
if (typeof opts.isAutoWhitespaceCommand !== 'undefined') {
this.isAutoWhitespaceCommand = opts.isAutoWhitespaceCommand;
}
if (typeof opts.shouldRevealHorizontal !== 'undefined') {
this.shouldRevealHorizontal = opts.shouldRevealHorizontal;
}
if (typeof opts.cursorPositionChangeReason !== 'undefined') {
this.cursorPositionChangeReason = opts.cursorPositionChangeReason;
}
}
}
......
......@@ -60,7 +60,10 @@ export class DeleteOperations {
let deleteSelection = new Range(lineNumber, column, lineNumber, maxColumn);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
......@@ -99,7 +102,10 @@ export class DeleteOperations {
position.column + 1
);
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
public static deleteLeft(config: CursorConfiguration, model: ICursorSimpleModel, cursor: CursorModelState): EditOperationResult {
......@@ -180,7 +186,10 @@ export class DeleteOperations {
let deleteSelection = new Range(lineNumber, 1, lineNumber, column);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
......@@ -229,7 +238,10 @@ export class DeleteOperations {
);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: true,
shouldPushStackElementAfter: true
});
} else {
return null;
}
......
......@@ -167,7 +167,10 @@ export class TypeOperations {
let lineMaxColumn = model.getLineMaxColumn(selection.startLineNumber);
if (selection.startColumn !== 1 || selection.endColumn !== lineMaxColumn) {
// This is a single line selection that is not the entire line
return new EditOperationResult(this._replaceJumpToNextIndent(config, model, selection));
return new EditOperationResult(this._replaceJumpToNextIndent(config, model, selection), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
......@@ -179,7 +182,10 @@ export class TypeOperations {
let pos = cursor.position;
let startColumn = Math.max(1, pos.column - replaceCharCnt);
let range = new Range(pos.lineNumber, startColumn, pos.lineNumber, pos.column);
return new EditOperationResult(new ReplaceCommand(range, txt));
return new EditOperationResult(new ReplaceCommand(range, txt), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
public static typeCommand(range: Range, text: string, keepPosition: boolean): ICommand {
......@@ -262,7 +268,10 @@ export class TypeOperations {
}
let typeSelection = new Range(position.lineNumber, position.column, position.lineNumber, position.column + 1);
return new EditOperationResult(new ReplaceCommand(typeSelection, ch));
return new EditOperationResult(new ReplaceCommand(typeSelection, ch), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
private static _typeInterceptorAutoClosingOpenChar(config: CursorConfiguration, model: ITokenizedModel, cursor: CursorModelState, ch: string): EditOperationResult {
......@@ -426,14 +435,20 @@ export class TypeOperations {
}
public static typeWithoutInterceptors(config: CursorConfiguration, model: ITokenizedModel, cursor: CursorModelState, str: string): EditOperationResult {
return new EditOperationResult(TypeOperations.typeCommand(cursor.selection, str, false));
return new EditOperationResult(TypeOperations.typeCommand(cursor.selection, str, false), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
public static lineInsertBefore(config: CursorConfiguration, model: ITokenizedModel, cursor: CursorModelState): EditOperationResult {
let lineNumber = cursor.position.lineNumber;
if (lineNumber === 1) {
return new EditOperationResult(new ReplaceCommandWithoutChangingPosition(new Range(1, 1, 1, 1), '\n'));
return new EditOperationResult(new ReplaceCommandWithoutChangingPosition(new Range(1, 1, 1, 1), '\n'), {
shouldPushStackElementBefore: true,
shouldPushStackElementAfter: true
});
}
lineNumber--;
......
......@@ -270,7 +270,10 @@ export class WordOperations {
let lastNonWhitespace = strings.lastNonWhitespaceIndex(lineContent, startIndex);
if (lastNonWhitespace + 1 < startIndex) {
let deleteRange = new Range(position.lineNumber, lastNonWhitespace + 2, position.lineNumber, position.column);
return new EditOperationResult(new ReplaceCommand(deleteRange, ''));
return new EditOperationResult(new ReplaceCommand(deleteRange, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
return null;
}
......@@ -323,7 +326,10 @@ export class WordOperations {
let deleteSelection = new Range(lineNumber, column, lineNumber, position.column);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
......@@ -349,7 +355,10 @@ export class WordOperations {
if (startIndex + 1 < firstNonWhitespace) {
// bingo
let deleteRange = new Range(position.lineNumber, position.column, position.lineNumber, firstNonWhitespace + 1);
return new EditOperationResult(new ReplaceCommand(deleteRange, ''));
return new EditOperationResult(new ReplaceCommand(deleteRange, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
return null;
}
......@@ -419,7 +428,10 @@ export class WordOperations {
let deleteSelection = new Range(lineNumber, column, position.lineNumber, position.column);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''));
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
......
......@@ -6,7 +6,7 @@
import { illegalArgument } from 'vs/base/common/errors';
import { CursorMoveHelper } from 'vs/editor/common/controller/cursorMoveHelper';
import { EditOperationResult, CursorConfiguration, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';
import { CursorConfiguration, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
......@@ -14,8 +14,6 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { IDisposable } from 'vs/base/common/lifecycle';
import { MoveOperations, MoveOperationResult } from 'vs/editor/common/controller/cursorMoveOperations';
import { WordType, WordOperations, WordNavigationType } from 'vs/editor/common/controller/cursorWordOperations';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
export interface IOneCursorOperationContext {
cursorPositionChangeReason: editorCommon.CursorChangeReason;
......@@ -1117,150 +1115,6 @@ export class OneCursorOp {
}
// -------------------- STOP handlers that simply change cursor state
// -------------------- START type interceptors & co.
public static lineInsertBefore(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.lineInsertBefore(cursor.config, cursor.model, cursor.modelState)
);
}
public static lineInsertAfter(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.lineInsertAfter(cursor.config, cursor.model, cursor.modelState)
);
}
public static lineBreakInsert(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.lineBreakInsert(cursor.config, cursor.model, cursor.modelState)
);
}
public static actualType(cursor: OneCursor, text: string, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.typeWithoutInterceptors(cursor.config, cursor.model, cursor.modelState, text)
);
}
public static type(cursor: OneCursor, ch: string, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.typeWithInterceptors(cursor.config, cursor.model, cursor.modelState, ch)
);
}
public static replacePreviousChar(cursor: OneCursor, txt: string, replaceCharCnt: number, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.replacePreviousChar(cursor.config, cursor.model, cursor.modelState, txt, replaceCharCnt)
);
}
public static tab(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.tab(cursor.config, cursor.model, cursor.modelState)
);
}
public static indent(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.indent(cursor.config, cursor.model, cursor.modelState)
);
}
public static outdent(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.outdent(cursor.config, cursor.model, cursor.modelState)
);
}
public static paste(cursor: OneCursor, text: string, pasteOnNewLine: boolean, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
TypeOperations.paste(cursor.config, cursor.model, cursor.modelState, text, pasteOnNewLine)
);
}
// -------------------- END type interceptors & co.
// -------------------- START delete handlers & co.
private static _applyEditOperation(ctx: IOneCursorOperationContext, r: EditOperationResult): boolean {
if (r) {
ctx.executeCommand = r.command;
ctx.shouldPushStackElementBefore = r.shouldPushStackElementBefore;
ctx.shouldPushStackElementAfter = r.shouldPushStackElementAfter;
ctx.isAutoWhitespaceCommand = r.isAutoWhitespaceCommand;
ctx.shouldRevealHorizontal = r.shouldRevealHorizontal;
ctx.cursorPositionChangeReason = r.cursorPositionChangeReason;
}
return true;
}
public static deleteLeft(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
DeleteOperations.deleteLeft(cursor.config, cursor.model, cursor.modelState)
);
}
public static deleteWordLeft(cursor: OneCursor, whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
WordOperations.deleteWordLeft(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType)
);
}
public static deleteRight(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
DeleteOperations.deleteRight(cursor.config, cursor.model, cursor.modelState)
);
}
public static deleteWordRight(cursor: OneCursor, whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
WordOperations.deleteWordRight(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType)
);
}
public static deleteAllLeft(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
DeleteOperations.deleteAllLeft(cursor.config, cursor.model, cursor.modelState)
);
}
public static deleteAllRight(cursor: OneCursor, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
DeleteOperations.deleteAllRight(cursor.config, cursor.model, cursor.modelState)
);
}
public static cut(cursor: OneCursor, enableEmptySelectionClipboard: boolean, ctx: IOneCursorOperationContext): boolean {
return this._applyEditOperation(
ctx,
DeleteOperations.cut(cursor.config, cursor.model, cursor.modelState, enableEmptySelectionClipboard)
);
}
// -------------------- END delete handlers & co.
}
class Utils {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册