提交 2342d2e2 编写于 作者: A Alex Dima

Simplify cursor.trigger

上级 80e93de8
......@@ -20,8 +20,6 @@ import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperat
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
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 { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
class CursorOperationArgs<T> {
public readonly eventSource: string;
......@@ -486,14 +484,6 @@ export class Cursor extends Disposable implements ICursors {
public trigger(source: string, handlerId: string, payload: any): void {
if (!this._handlers.hasOwnProperty(handlerId)) {
const command = CommonEditorRegistry.getEditorCommand(handlerId);
if (!command || !(command instanceof CoreEditorCommand)) {
return;
}
payload = payload || {};
payload.source = source;
command.runCoreEditorCommand(this, payload);
return;
}
const handler = this._handlers[handlerId];
......@@ -509,7 +499,6 @@ export class Cursor extends Disposable implements ICursors {
this._handlers[H.CompositionStart] = (args) => this._compositionStart(args);
this._handlers[H.CompositionEnd] = (args) => this._compositionEnd(args);
this._handlers[H.Paste] = (args) => this._paste(args);
this._handlers[H.Cut] = (args) => this._cut(args);
this._handlers[H.Undo] = (args) => this._undo(args);
......
......@@ -303,7 +303,7 @@ suite('FindModel', () => {
]
);
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
editor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(6, 20)
});
......@@ -663,7 +663,7 @@ suite('FindModel', () => {
]
);
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
editor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(6, 20)
});
assertFindState(
......@@ -1150,7 +1150,7 @@ suite('FindModel', () => {
]
);
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
editor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(6, 20)
});
assertFindState(
......@@ -1311,7 +1311,7 @@ suite('FindModel', () => {
]
);
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
editor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(6, 20)
});
assertFindState(
......@@ -1741,7 +1741,7 @@ suite('FindModel', () => {
findState.change({ searchString: 'hello(?=\\sworld)', replaceString: 'hi', isRegex: true }, false);
let findModel = new FindModelBoundToEditorModel(editor, findState);
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
editor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(8, 14)
});
......
......@@ -478,13 +478,13 @@ suite('Editor Contrib - Line Operations', () => {
new Selection(2, 4, 2, 4)
]);
cursor.trigger('tests', Handler.Undo, {});
editor.trigger('tests', Handler.Undo, {});
assert.deepEqual(editor.getSelections(), [
new Selection(1, 3, 1, 3),
new Selection(1, 6, 1, 6),
new Selection(3, 4, 3, 4)
]);
cursor.trigger('tests', Handler.Redo, {});
editor.trigger('tests', Handler.Redo, {});
assert.deepEqual(editor.getSelections(), [
new Selection(1, 3, 1, 3),
new Selection(2, 4, 2, 4)
......
......@@ -1863,7 +1863,7 @@ suite('Editor Controller - Cursor Configuration', () => {
],
modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
}, (model, cursor) => {
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(1, 21) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(1, 21), source: 'keyboard' });
cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
assert.equal(model.getLineContent(1), ' \tMy First Line\t ');
assert.equal(model.getLineContent(2), ' ');
......@@ -1890,56 +1890,56 @@ suite('Editor Controller - Cursor Configuration', () => {
withMockCodeEditor(null, { model: model }, (editor, cursor) => {
// Tab on column 1
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 1) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 1) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), ' My Second Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 2
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 2) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 2) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'M y Second Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 3
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 3) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 3) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 4
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 4) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 4) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 5
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 5) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 5) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My S econd Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 5
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 5) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 5) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My S econd Line123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 13
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 13) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 13) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My Second Li ne123');
cursorCommand(cursor, H.Undo, null, 'keyboard');
// Tab on column 14
assert.equal(model.getLineContent(2), 'My Second Line123');
cursorCommand(cursor, CoreNavigationCommands.MoveTo.id, { position: new Position(2, 14) }, 'keyboard');
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursor, { position: new Position(2, 14) });
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
assert.equal(model.getLineContent(2), 'My Second Lin e123');
});
......
......@@ -13,14 +13,13 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import WorkbenchEditorService = require('vs/workbench/services/editor/common/editorService');
import { RangeHighlightDecorations } from 'vs/workbench/common/editor/rangeDecorations';
import { Model } from 'vs/editor/common/model/model';
import { mockCodeEditor, MockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import { mockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import { TextModel } from 'vs/editor/common/model/textModel';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
......@@ -33,7 +32,6 @@ suite('Editor - Range decorations', () => {
let modelService: IModelService;
let modeService: IModeService;
let codeEditor: editorCommon.ICommonCodeEditor;
let cursor: Cursor;
let model: Model;
let text: string;
let testObject: RangeHighlightDecorations;
......@@ -47,7 +45,6 @@ suite('Editor - Range decorations', () => {
text = 'LINE1' + '\n' + 'LINE2' + '\n' + 'LINE3' + '\n' + 'LINE4' + '\r\n' + 'LINE5';
model = aModel(URI.file('some_file'));
codeEditor = mockCodeEditor([], { model });
cursor = (<MockCodeEditor>codeEditor).getCursor();
mockEditorService(codeEditor.getModel().uri);
instantiationService.stub(WorkbenchEditorService.IWorkbenchEditorService, 'getActiveEditor', { getControl: () => { return codeEditor; } });
......@@ -111,7 +108,7 @@ suite('Editor - Range decorations', () => {
test('highlight is removed on cursor position change', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
cursor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
codeEditor.trigger('mouse', CoreNavigationCommands.MoveTo.id, {
position: new Position(2, 1)
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册