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

The cursor gets passed in the ViewModel

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