提交 dcbe78a1 编写于 作者: A Alex Dima

The cursor gets passed in the ViewModel

上级 7a765323
......@@ -13,7 +13,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import { IContextKey, IContextKeyServiceTarget, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { CommonEditorConfiguration } from 'vs/editor/common/config/commonEditorConfig';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { CursorColumns, IViewModelHelper, ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { CursorColumns, ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Selection, ISelection } from 'vs/editor/common/core/selection';
......@@ -863,23 +863,6 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
this.viewModel = new ViewModel(this.id, this._configuration, this.model);
let viewModelHelper: IViewModelHelper = {
viewModel: this.viewModel,
coordinatesConverter: this.viewModel.coordinatesConverter,
getScrollTop: (): number => {
return this.viewModel.viewLayout.getScrollTop();
},
getCompletelyVisibleViewRange: (): Range => {
return this.viewModel.getCompletelyVisibleViewRange();
},
getCompletelyVisibleViewRangeAtScrollTop: (scrollTop: number): Range => {
return this.viewModel.getCompletelyVisibleViewRangeAtScrollTop(scrollTop);
},
getVerticalOffsetForViewLineNumber: (viewLineNumber: number): number => {
return this.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewLineNumber);
}
};
this.listenersToRemove.push(this.model.addBulkListener((events) => {
for (let i = 0, len = events.length; i < len; i++) {
let eventType = events[i].type;
......@@ -917,7 +900,7 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
this.cursor = new Cursor(
this._configuration,
this.model,
viewModelHelper
this.viewModel
);
this.viewCursor = new ViewModelCursors(
......
......@@ -20,6 +20,7 @@ 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 { IViewModel } from "vs/editor/common/viewModel/viewModel";
export class Cursor extends Disposable implements ICursors {
......@@ -44,11 +45,29 @@ export class Cursor extends Disposable implements ICursors {
private _isDoingComposition: boolean;
private _columnSelectData: IColumnSelectData;
constructor(configuration: editorCommon.IConfiguration, model: editorCommon.IModel, viewModelHelper: IViewModelHelper) {
constructor(configuration: editorCommon.IConfiguration, model: editorCommon.IModel, viewModel: IViewModel) {
super();
this._eventEmitter = this._register(new EventEmitter());
this._configuration = configuration;
this._model = model;
let viewModelHelper: IViewModelHelper = {
viewModel: viewModel,
coordinatesConverter: viewModel.coordinatesConverter,
getScrollTop: (): number => {
return viewModel.viewLayout.getScrollTop();
},
getCompletelyVisibleViewRange: (): Range => {
return viewModel.getCompletelyVisibleViewRange();
},
getCompletelyVisibleViewRangeAtScrollTop: (scrollTop: number): Range => {
return viewModel.getCompletelyVisibleViewRangeAtScrollTop(scrollTop);
},
getVerticalOffsetForViewLineNumber: (viewLineNumber: number): number => {
return viewModel.viewLayout.getVerticalOffsetForLineNumber(viewLineNumber);
}
};
this._viewModelHelper = viewModelHelper;
this.context = new CursorContext(this._configuration, this._model, this._viewModelHelper);
this._cursors = new CursorCollection(this.context);
......
......@@ -120,6 +120,8 @@ export interface IViewModel {
getDecorationsInViewport(visibleRange: Range): ViewModelDecoration[];
getViewLineRenderingData(visibleRange: Range, lineNumber: number): ViewLineRenderingData;
getMinimapLinesRenderingData(startLineNumber: number, endLineNumber: number, needed: boolean[]): MinimapLinesRenderingData;
getCompletelyVisibleViewRange(): Range;
getCompletelyVisibleViewRangeAtScrollTop(scrollTop: number): Range;
getTabSize(): number;
getLineCount(): number;
......@@ -127,6 +129,8 @@ export interface IViewModel {
getLineIndentGuide(lineNumber: number): number;
getLineMinColumn(lineNumber: number): number;
getLineMaxColumn(lineNumber: number): number;
getLineFirstNonWhitespaceColumn(lineNumber: number): number;
getLineLastNonWhitespaceColumn(lineNumber: number): number;
getAllOverviewRulerDecorations(): ViewModelDecoration[];
getValueInRange(range: Range, eol: EndOfLinePreference): string;
......
......@@ -5,14 +5,12 @@
'use strict';
import * as assert from 'assert';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { Model } from 'vs/editor/common/model/model';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
import { viewModelHelper } from 'vs/editor/test/common/editorTestUtils';
import { withMockCodeEditor } from "vs/editor/test/common/mocks/mockCodeEditor";
export function testCommand(
lines: string[],
......@@ -22,22 +20,19 @@ export function testCommand(
expectedLines: string[],
expectedSelection: Selection
): void {
let model = Model.createFromString(lines.join('\n'), undefined, languageIdentifier);
let config = new TestConfiguration(null);
let cursor = new Cursor(config, model, viewModelHelper(model));
withMockCodeEditor(null, { model: model }, (editor, cursor) => {
cursor.setSelections('tests', [selection]);
cursor.setSelections('tests', [selection]);
cursor.trigger('tests', editorCommon.Handler.ExecuteCommand, commandFactory(cursor.getSelection()));
cursor.trigger('tests', editorCommon.Handler.ExecuteCommand, commandFactory(cursor.getSelection()));
assert.deepEqual(model.getLinesContent(), expectedLines);
assert.deepEqual(model.getLinesContent(), expectedLines);
let actualSelection = cursor.getSelection();
assert.deepEqual(actualSelection.toString(), expectedSelection.toString());
let actualSelection = cursor.getSelection();
assert.deepEqual(actualSelection.toString(), expectedSelection.toString());
cursor.dispose();
config.dispose();
});
model.dispose();
}
......
......@@ -5,36 +5,30 @@
'use strict';
import * as assert from 'assert';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/editorCommon';
import { Model } from 'vs/editor/common/model/model';
import { ILineEdit, ModelLine, LineMarker, MarkersTracker } from 'vs/editor/common/model/modelLine';
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
import { viewModelHelper } from 'vs/editor/test/common/editorTestUtils';
import { withMockCodeEditor } from "vs/editor/test/common/mocks/mockCodeEditor";
const NO_TAB_SIZE = 0;
function testCommand(lines: string[], selections: Selection[], edits: IIdentifiedSingleEditOperation[], expectedLines: string[], expectedSelections: Selection[]): void {
let model = Model.createFromString(lines.join('\n'));
let config = new TestConfiguration(null);
let cursor = new Cursor(config, model, viewModelHelper(model));
withMockCodeEditor(lines, {}, (editor, cursor) => {
const model = editor.getModel();
cursor.setSelections('tests', selections);
cursor.setSelections('tests', selections);
model.applyEdits(edits);
model.applyEdits(edits);
assert.deepEqual(model.getLinesContent(), expectedLines);
assert.deepEqual(model.getLinesContent(), expectedLines);
let actualSelections = cursor.getSelections();
assert.deepEqual(actualSelections.map(s => s.toString()), expectedSelections.map(s => s.toString()));
let actualSelections = cursor.getSelections();
assert.deepEqual(actualSelections.map(s => s.toString()), expectedSelections.map(s => s.toString()));
cursor.dispose();
config.dispose();
model.dispose();
});
}
function testLineEditMarker(text: string, column: number, stickToPreviousCharacter: boolean, edit: ILineEdit, expectedColumn: number): void {
......
......@@ -21,12 +21,12 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { viewModelHelper } from 'vs/editor/test/common/editorTestUtils';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { CoreNavigationCommands, CoreEditingCommands } from 'vs/editor/common/controller/coreCommands';
import { withMockCodeEditor } from "vs/editor/test/common/mocks/mockCodeEditor";
import { TextModel } from "vs/editor/common/model/textModel";
import { ViewModel } from "vs/editor/common/viewModel/viewModelImpl";
let H = Handler;
......@@ -136,6 +136,7 @@ suite('Editor Controller - Cursor', () => {
let thisModel: Model;
let thisConfiguration: TestConfiguration;
let thisViewModel: ViewModel;
let thisCursor: Cursor;
setup(() => {
......@@ -148,11 +149,14 @@ suite('Editor Controller - Cursor', () => {
thisModel = Model.createFromString(text);
thisConfiguration = new TestConfiguration(null);
thisCursor = new Cursor(thisConfiguration, thisModel, viewModelHelper(thisModel));
thisViewModel = new ViewModel(0, thisConfiguration, thisModel);
thisCursor = new Cursor(thisConfiguration, thisModel, thisViewModel);
});
teardown(() => {
thisCursor.dispose();
thisViewModel.dispose();
thisModel.dispose();
thisConfiguration.dispose();
});
......@@ -700,39 +704,37 @@ suite('Editor Controller - Cursor', () => {
});
test('column select 1', () => {
let model = Model.createFromString([
withMockCodeEditor([
'\tprivate compute(a:number): boolean {',
'\t\tif (a + 3 === 0 || a + 5 === 0) {',
'\t\t\treturn false;',
'\t\t}',
'\t}'
].join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
], {}, (editor, cursor) => {
moveTo(cursor, 1, 7, false);
assertCursor(cursor, new Position(1, 7));
moveTo(cursor, 1, 7, false);
assertCursor(cursor, new Position(1, 7));
CoreNavigationCommands.ColumnSelect.runCoreEditorCommand(cursor, {
position: new Position(4, 4),
viewPosition: new Position(4, 4),
mouseColumn: 15
});
CoreNavigationCommands.ColumnSelect.runCoreEditorCommand(cursor, {
position: new Position(4, 4),
viewPosition: new Position(4, 4),
mouseColumn: 15
});
let expectedSelections = [
new Selection(1, 7, 1, 12),
new Selection(2, 4, 2, 9),
new Selection(3, 3, 3, 6),
new Selection(4, 4, 4, 4),
];
let expectedSelections = [
new Selection(1, 7, 1, 12),
new Selection(2, 4, 2, 9),
new Selection(3, 3, 3, 6),
new Selection(4, 4, 4, 4),
];
assertCursor(cursor, expectedSelections);
assertCursor(cursor, expectedSelections);
cursor.dispose();
model.dispose();
});
});
test('issue #4905 - column select is biased to the right', () => {
let model = Model.createFromString([
const model = Model.createFromString([
'var gulp = require("gulp");',
'var path = require("path");',
'var rimraf = require("rimraf");',
......@@ -741,7 +743,9 @@ suite('Editor Controller - Cursor', () => {
'var concat = require("gulp-concat");',
'var newer = require("gulp-newer");',
].join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
const config = new TestConfiguration(null);
const viewModel = new ViewModel(0, config, model);
const cursor = new Cursor(config, model, viewModel);
moveTo(cursor, 1, 4, false);
assertCursor(cursor, new Position(1, 4));
......@@ -760,11 +764,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor.dispose();
viewModel.dispose();
config.dispose();
model.dispose();
});
test('issue #20087: column select with mouse', () => {
let model = Model.createFromString([
const model = Model.createFromString([
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" Key="SomeKey" value="000"/>',
......@@ -776,7 +782,9 @@ suite('Editor Controller - Cursor', () => {
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" key="SomeKey" value="00X"/>',
].join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
const config = new TestConfiguration(null);
const viewModel = new ViewModel(0, config, model);
const cursor = new Cursor(config, model, viewModel);
moveTo(cursor, 10, 10, false);
assertCursor(cursor, new Position(10, 10));
......@@ -818,11 +826,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor.dispose();
viewModel.dispose();
config.dispose();
model.dispose();
});
test('issue #20087: column select with keyboard', () => {
let model = Model.createFromString([
const model = Model.createFromString([
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" Key="SomeKey" value="000"/>',
......@@ -834,7 +844,9 @@ suite('Editor Controller - Cursor', () => {
'<property id="SomeThing" key="SomeKey" value="000"/>',
'<property id="SomeThing" key="SomeKey" value="00X"/>',
].join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
const config = new TestConfiguration(null);
const viewModel = new ViewModel(0, config, model);
const cursor = new Cursor(config, model, viewModel);
moveTo(cursor, 10, 10, false);
assertCursor(cursor, new Position(10, 10));
......@@ -866,11 +878,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor.dispose();
viewModel.dispose();
config.dispose();
model.dispose();
});
test('column select with keyboard', () => {
let model = Model.createFromString([
const model = Model.createFromString([
'var gulp = require("gulp");',
'var path = require("path");',
'var rimraf = require("rimraf");',
......@@ -879,7 +893,9 @@ suite('Editor Controller - Cursor', () => {
'var concat = require("gulp-concat");',
'var newer = require("gulp-newer");',
].join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
const config = new TestConfiguration(null);
const viewModel = new ViewModel(0, config, model);
const cursor = new Cursor(config, model, viewModel);
moveTo(cursor, 1, 4, false);
assertCursor(cursor, new Position(1, 4));
......@@ -1076,6 +1092,8 @@ suite('Editor Controller - Cursor', () => {
]);
cursor.dispose();
viewModel.dispose();
config.dispose();
model.dispose();
});
});
......@@ -1438,45 +1456,41 @@ suite('Editor Controller - Regression tests', () => {
});
test('bug #16740: [editor] Cut line doesn\'t quite cut the last line', () => {
// Part 1 => there is text on the last line
let text = [
withMockCodeEditor([
'asdasd',
'qwerty'
];
let model = Model.createFromString(text.join('\n'));
let cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
], {}, (editor, cursor) => {
const model = editor.getModel();
moveTo(cursor, 2, 1, false);
assertCursor(cursor, new Selection(2, 1, 2, 1));
moveTo(cursor, 2, 1, false);
assertCursor(cursor, new Selection(2, 1, 2, 1));
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), 'asdasd');
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), 'asdasd');
cursor.dispose();
model.dispose();
});
// Part 2 => there is no text on the last line
text = [
withMockCodeEditor([
'asdasd',
''
];
model = Model.createFromString(text.join('\n'));
cursor = new Cursor(new TestConfiguration(null), model, viewModelHelper(model));
moveTo(cursor, 2, 1, false);
assertCursor(cursor, new Selection(2, 1, 2, 1));
], {}, (editor, cursor) => {
const model = editor.getModel();
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), 'asdasd');
moveTo(cursor, 2, 1, false);
assertCursor(cursor, new Selection(2, 1, 2, 1));
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), '');
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), 'asdasd');
cursor.dispose();
model.dispose();
cursorCommand(cursor, H.Cut, null, 'keyboard');
assert.equal(model.getLineCount(), 1);
assert.equal(model.getLineContent(1), '');
});
});
test('Bug #11476: Double bracket surrounding + undo is broken', () => {
......@@ -2756,11 +2770,13 @@ interface ICursorOpts {
function usingCursor(opts: ICursorOpts, callback: (model: Model, cursor: Cursor) => void): void {
let model = Model.createFromString(opts.text.join('\n'), opts.modelOpts, opts.languageIdentifier);
let config = new TestConfiguration(opts.editorOpts);
let cursor = new Cursor(config, model, viewModelHelper(model));
let viewModel = new ViewModel(0, config, model);
let cursor = new Cursor(config, model, viewModel);
callback(model, cursor);
cursor.dispose();
viewModel.dispose();
config.dispose();
model.dispose();
}
......
......@@ -11,18 +11,18 @@ import { ITextModelCreationOptions } from 'vs/editor/common/editorCommon';
import { Model } from 'vs/editor/common/model/model';
import { IMode } from 'vs/editor/common/modes';
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
import { viewModelHelper as aViewModelHelper } from 'vs/editor/test/common/editorTestUtils';
import { CursorMove } from 'vs/editor/common/controller/cursorMoveCommands';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IViewModelHelper } from 'vs/editor/common/controller/cursorCommon';
import { CoreNavigationCommands } from 'vs/editor/common/controller/coreCommands';
import { ViewModel } from "vs/editor/common/viewModel/viewModelImpl";
suite('Cursor move command test', () => {
let thisModel: Model;
let thisConfiguration: TestConfiguration;
let thisViewModel: ViewModel;
let thisCursor: Cursor;
setup(() => {
......@@ -36,16 +36,18 @@ suite('Cursor move command test', () => {
thisModel = Model.createFromString(text);
thisConfiguration = new TestConfiguration(null);
thisViewModel = new ViewModel(0, thisConfiguration, thisModel);
thisCursor = new Cursor(thisConfiguration, thisModel, thisViewModel);
});
teardown(() => {
thisCursor.dispose();
thisViewModel.dispose();
thisModel.dispose();
thisConfiguration.dispose();
});
test('move left should move to left character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor);
......@@ -54,7 +56,6 @@ suite('Cursor move command test', () => {
});
test('move left should move to left by n characters', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor, 3);
......@@ -63,7 +64,6 @@ suite('Cursor move command test', () => {
});
test('move left should move to left by half line', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor, 1, CursorMove.RawUnit.HalfLine);
......@@ -72,7 +72,6 @@ suite('Cursor move command test', () => {
});
test('move left moves to previous line', () => {
thisCursor = aCursor();
moveTo(thisCursor, 2, 3);
moveLeft(thisCursor, 10);
......@@ -81,7 +80,6 @@ suite('Cursor move command test', () => {
});
test('move right should move to right character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 5);
moveRight(thisCursor);
......@@ -90,7 +88,6 @@ suite('Cursor move command test', () => {
});
test('move right should move to right by n characters', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 2);
moveRight(thisCursor, 6);
......@@ -99,7 +96,6 @@ suite('Cursor move command test', () => {
});
test('move right should move to right by half line', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 4);
moveRight(thisCursor, 1, CursorMove.RawUnit.HalfLine);
......@@ -108,7 +104,6 @@ suite('Cursor move command test', () => {
});
test('move right moves to next line', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveRight(thisCursor, 100);
......@@ -117,14 +112,12 @@ suite('Cursor move command test', () => {
});
test('move to first character of line from middle', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveToLineStart(thisCursor);
cursorEqual(thisCursor, 1, 1);
});
test('move to first character of line from first non white space character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 6);
moveToLineStart(thisCursor);
......@@ -133,7 +126,6 @@ suite('Cursor move command test', () => {
});
test('move to first character of line from first character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 1);
moveToLineStart(thisCursor);
......@@ -142,7 +134,6 @@ suite('Cursor move command test', () => {
});
test('move to first non white space character of line from middle', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveToLineFirstNonWhiteSpaceCharacter(thisCursor);
......@@ -151,7 +142,6 @@ suite('Cursor move command test', () => {
});
test('move to first non white space character of line from first non white space character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 6);
moveToLineFirstNonWhiteSpaceCharacter(thisCursor);
......@@ -160,7 +150,6 @@ suite('Cursor move command test', () => {
});
test('move to first non white space character of line from first character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 1);
moveToLineFirstNonWhiteSpaceCharacter(thisCursor);
......@@ -169,7 +158,6 @@ suite('Cursor move command test', () => {
});
test('move to end of line from middle', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveToLineEnd(thisCursor);
......@@ -178,7 +166,6 @@ suite('Cursor move command test', () => {
});
test('move to end of line from last non white space character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 19);
moveToLineEnd(thisCursor);
......@@ -187,7 +174,6 @@ suite('Cursor move command test', () => {
});
test('move to end of line from line end', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 21);
moveToLineEnd(thisCursor);
......@@ -196,7 +182,6 @@ suite('Cursor move command test', () => {
});
test('move to last non white space character from middle', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveToLineLastNonWhiteSpaceCharacter(thisCursor);
......@@ -205,7 +190,6 @@ suite('Cursor move command test', () => {
});
test('move to last non white space character from last non white space character', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 19);
moveToLineLastNonWhiteSpaceCharacter(thisCursor);
......@@ -214,7 +198,6 @@ suite('Cursor move command test', () => {
});
test('move to last non white space character from line end', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 21);
moveToLineLastNonWhiteSpaceCharacter(thisCursor);
......@@ -223,7 +206,6 @@ suite('Cursor move command test', () => {
});
test('move to center of line not from center', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 8);
moveToLineCenter(thisCursor);
......@@ -232,7 +214,6 @@ suite('Cursor move command test', () => {
});
test('move to center of line from center', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 11);
moveToLineCenter(thisCursor);
......@@ -241,7 +222,6 @@ suite('Cursor move command test', () => {
});
test('move to center of line from start', () => {
thisCursor = aCursor();
moveToLineStart(thisCursor);
moveToLineCenter(thisCursor);
......@@ -250,7 +230,6 @@ suite('Cursor move command test', () => {
});
test('move to center of line from end', () => {
thisCursor = aCursor();
moveToLineEnd(thisCursor);
moveToLineCenter(thisCursor);
......@@ -259,7 +238,6 @@ suite('Cursor move command test', () => {
});
test('move up by cursor move command', () => {
thisCursor = aCursor();
moveTo(thisCursor, 3, 5);
cursorEqual(thisCursor, 3, 5);
......@@ -272,7 +250,6 @@ suite('Cursor move command test', () => {
});
test('move up by model line cursor move command', () => {
thisCursor = aCursor();
moveTo(thisCursor, 3, 5);
cursorEqual(thisCursor, 3, 5);
......@@ -285,7 +262,6 @@ suite('Cursor move command test', () => {
});
test('move down by model line cursor move command', () => {
thisCursor = aCursor();
moveTo(thisCursor, 3, 5);
cursorEqual(thisCursor, 3, 5);
......@@ -298,7 +274,6 @@ suite('Cursor move command test', () => {
});
test('move up with selection by cursor move command', () => {
thisCursor = aCursor();
moveTo(thisCursor, 3, 5);
cursorEqual(thisCursor, 3, 5);
......@@ -311,7 +286,6 @@ suite('Cursor move command test', () => {
});
test('move up and down with tabs by cursor move command', () => {
thisCursor = aCursor();
moveTo(thisCursor, 1, 5);
cursorEqual(thisCursor, 1, 5);
......@@ -333,7 +307,6 @@ suite('Cursor move command test', () => {
});
test('move up and down with end of lines starting from a long one by cursor move command', () => {
thisCursor = aCursor();
moveToEndOfLine(thisCursor);
cursorEqual(thisCursor, 1, 21);
......@@ -355,9 +328,7 @@ suite('Cursor move command test', () => {
});
test('move to view top line moves to first visible line if it is first line', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
moveTo(thisCursor, 2, 2);
moveToTop(thisCursor);
......@@ -366,9 +337,7 @@ suite('Cursor move command test', () => {
});
test('move to view top line moves to top visible line when first line is not visible', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(2, 1, 10, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 10, 1);
moveTo(thisCursor, 4, 1);
moveToTop(thisCursor);
......@@ -377,9 +346,7 @@ suite('Cursor move command test', () => {
});
test('move to view top line moves to nth line from top', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
moveTo(thisCursor, 4, 1);
moveToTop(thisCursor, 3);
......@@ -388,9 +355,7 @@ suite('Cursor move command test', () => {
});
test('move to view top line moves to last line if n is greater than last visible line number', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(1, 1, 3, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 3, 1);
moveTo(thisCursor, 2, 2);
moveToTop(thisCursor, 4);
......@@ -399,9 +364,7 @@ suite('Cursor move command test', () => {
});
test('move to view center line moves to the center line', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(3, 1, 3, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(3, 1, 3, 1);
moveTo(thisCursor, 2, 2);
moveToCenter(thisCursor);
......@@ -410,9 +373,7 @@ suite('Cursor move command test', () => {
});
test('move to view bottom line moves to last visible line if it is last line', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
moveTo(thisCursor, 2, 2);
moveToBottom(thisCursor);
......@@ -421,9 +382,7 @@ suite('Cursor move command test', () => {
});
test('move to view bottom line moves to last visible line when last line is not visible', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(2, 1, 3, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 3, 1);
moveTo(thisCursor, 2, 2);
moveToBottom(thisCursor);
......@@ -432,9 +391,7 @@ suite('Cursor move command test', () => {
});
test('move to view bottom line moves to nth line from bottom', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
moveTo(thisCursor, 4, 1);
moveToBottom(thisCursor, 3);
......@@ -443,20 +400,13 @@ suite('Cursor move command test', () => {
});
test('move to view bottom line moves to first line if n is lesser than first visible line number', () => {
let viewModelHelper = aViewModelHelper(thisModel);
viewModelHelper.getCompletelyVisibleViewRange = () => new Range(2, 1, 5, 1);
thisCursor = aCursor(viewModelHelper);
thisViewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 5, 1);
moveTo(thisCursor, 4, 1);
moveToBottom(thisCursor, 5);
cursorEqual(thisCursor, 2, 2);
});
function aCursor(viewModelHelper?: IViewModelHelper): Cursor {
return new Cursor(thisConfiguration, thisModel, viewModelHelper || aViewModelHelper(thisModel));
}
});
interface ICursorOpts {
......
......@@ -5,59 +5,9 @@
'use strict';
import { Model } from 'vs/editor/common/model/model';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IModel } from 'vs/editor/common/editorCommon';
import { IViewModelHelper } from 'vs/editor/common/controller/cursorCommon';
export function withEditorModel(text: string[], callback: (model: Model) => void): void {
var model = Model.createFromString(text.join('\n'));
callback(model);
model.dispose();
}
export function viewModelHelper(model: IModel): IViewModelHelper {
return {
viewModel: model,
coordinatesConverter: {
convertViewPositionToModelPosition: (viewPosition: Position): Position => {
return viewPosition;
},
convertViewRangeToModelRange: (viewRange: Range): Range => {
return viewRange;
},
convertViewSelectionToModelSelection: (viewSelection: Selection): Selection => {
return viewSelection;
},
validateViewPosition: (viewPosition: Position, expectedModelPosition: Position): Position => {
return expectedModelPosition;
},
validateViewRange: (viewRange: Range, modelRange: Range): Range => {
return modelRange;
},
convertModelPositionToViewPosition: (modelPosition: Position): Position => {
return modelPosition;
},
convertModelRangeToViewRange: (modelRange: Range): Range => {
return modelRange;
},
convertModelSelectionToViewSelection: (modelSelection: Selection): Selection => {
return modelSelection;
},
modelPositionIsVisible: (modelPosition: Position): boolean => {
return true;
},
},
getScrollTop: (): number => 0,
getCompletelyVisibleViewRange: () => null,
getCompletelyVisibleViewRangeAtScrollTop: (scrollTop: number) => null,
getVerticalOffsetForViewLineNumber: (viewLineNumber: number) => 0
};
}
......@@ -71,12 +71,31 @@ export interface MockCodeEditorCreationOptions extends editorOptions.IEditorOpti
}
export function withMockCodeEditor(text: string[], options: MockCodeEditorCreationOptions, callback: (editor: MockCodeEditor, cursor: Cursor) => void): void {
let editor = <MockCodeEditor>mockCodeEditor(text, options);
// create a model if necessary and remember it in order to dispose it.
let modelToDispose: Model = null;
if (!options.model) {
modelToDispose = Model.createFromString(text.join('\n'));
options.model = modelToDispose;
}
let editor = <MockCodeEditor>_mockCodeEditor(options);
callback(editor, editor.getCursor());
if (modelToDispose) {
modelToDispose.dispose();
}
editor.dispose();
}
export function mockCodeEditor(text: string[], options: MockCodeEditorCreationOptions): CommonCodeEditor {
// TODO: who owns this model now?
if (!options.model) {
options.model = Model.createFromString(text.join('\n'));
}
return _mockCodeEditor(options);
}
function _mockCodeEditor(options: MockCodeEditorCreationOptions): CommonCodeEditor {
let contextKeyService = new MockContextKeyService();
......@@ -85,10 +104,6 @@ export function mockCodeEditor(text: string[], options: MockCodeEditorCreationOp
let instantiationService = new InstantiationService(services);
let editor = new MockCodeEditor(new MockScopeLocation(), options, instantiationService, contextKeyService);
let model = options.model || Model.createFromString(text.join('\n'));
if (model) {
editor.setModel(model);
}
editor.setModel(options.model);
return editor;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册