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

Simplify cursor.trigger

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