cursor.test.ts 96.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

A
Alex Dima 已提交
7
import * as assert from 'assert';
J
Johannes Rieken 已提交
8 9 10 11 12
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';
13
import {
A
Alex Dima 已提交
14
	EndOfLinePreference, EventType, Handler, IEditorOptions,
15
	DefaultEndOfLine, ITextModelCreationOptions, ICommand,
A
Alex Dima 已提交
16 17
	ITokenizedModel, IEditOperationBuilder, ICursorStateComputerData,
	ICursorPositionChangedEvent, ICursorSelectionChangedEvent
18
} from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
19 20 21 22 23 24
import { Model } from 'vs/editor/common/model/model';
import { IMode, IndentAction } from 'vs/editor/common/modes';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { MockConfiguration } from 'vs/editor/test/common/mocks/mockConfiguration';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { viewModelHelper } from 'vs/editor/test/common/editorTestUtils';
E
Erich Gamma 已提交
25

A
Alex Dima 已提交
26
let H = Handler;
E
Erich Gamma 已提交
27 28 29

// --------- utils

30
function cursorCommand(cursor: Cursor, command: string, extraData?: any, overwriteSource?: string) {
A
Alex Dima 已提交
31
	cursor.trigger(overwriteSource || 'tests', command, extraData);
E
Erich Gamma 已提交
32 33
}

A
Alex Dima 已提交
34 35
function moveTo(cursor: Cursor, lineNumber: number, column: number, inSelectionMode: boolean = false) {
	cursorCommand(cursor, inSelectionMode ? H.MoveToSelect : H.MoveTo, { position: new Position(lineNumber, column) });
E
Erich Gamma 已提交
36 37
}

A
Alex Dima 已提交
38
function moveLeft(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
39 40 41
	cursorCommand(cursor, inSelectionMode ? H.CursorLeftSelect : H.CursorLeft);
}

A
Alex Dima 已提交
42
function moveWordLeft(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
43 44
	cursorCommand(cursor, inSelectionMode ? H.CursorWordLeftSelect : H.CursorWordLeft);
}
45 46 47 48 49 50
function moveWordStartLeft(cursor: Cursor, inSelectionMode: boolean = false) {
	cursorCommand(cursor, inSelectionMode ? H.CursorWordStartLeftSelect : H.CursorWordStartLeft);
}
function moveWordEndLeft(cursor: Cursor, inSelectionMode: boolean = false) {
	cursorCommand(cursor, inSelectionMode ? H.CursorWordEndLeftSelect : H.CursorWordEndLeft);
}
E
Erich Gamma 已提交
51

A
Alex Dima 已提交
52
function moveRight(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
53 54 55
	cursorCommand(cursor, inSelectionMode ? H.CursorRightSelect : H.CursorRight);
}

A
Alex Dima 已提交
56
function moveWordRight(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
57 58
	cursorCommand(cursor, inSelectionMode ? H.CursorWordRightSelect : H.CursorWordRight);
}
59 60 61 62 63 64
function moveWordEndRight(cursor: Cursor, inSelectionMode: boolean = false) {
	cursorCommand(cursor, inSelectionMode ? H.CursorWordEndRightSelect : H.CursorWordEndRight);
}
function moveWordStartRight(cursor: Cursor, inSelectionMode: boolean = false) {
	cursorCommand(cursor, inSelectionMode ? H.CursorWordStartRightSelect : H.CursorWordStartRight);
}
E
Erich Gamma 已提交
65

A
Alex Dima 已提交
66
function moveDown(cursor: Cursor, linesCount: number, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
67 68 69
	if (linesCount === 1) {
		cursorCommand(cursor, inSelectionMode ? H.CursorDownSelect : H.CursorDown);
	} else {
70
		cursorCommand(cursor, inSelectionMode ? H.CursorPageDownSelect : H.CursorPageDown, { pageSize: linesCount });
E
Erich Gamma 已提交
71 72 73
	}
}

A
Alex Dima 已提交
74
function moveUp(cursor: Cursor, linesCount: number, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
75 76 77
	if (linesCount === 1) {
		cursorCommand(cursor, inSelectionMode ? H.CursorUpSelect : H.CursorUp);
	} else {
78
		cursorCommand(cursor, inSelectionMode ? H.CursorPageUpSelect : H.CursorPageUp, { pageSize: linesCount });
E
Erich Gamma 已提交
79 80 81
	}
}

A
Alex Dima 已提交
82
function moveToBeginningOfLine(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
83 84 85
	cursorCommand(cursor, inSelectionMode ? H.CursorHomeSelect : H.CursorHome);
}

A
Alex Dima 已提交
86
function moveToEndOfLine(cursor: Cursor, inSelectionMode: boolean = false) {
J
Johannes Rieken 已提交
87
	cursorCommand(cursor, inSelectionMode ? H.CursorEndSelect : H.CursorEnd);
E
Erich Gamma 已提交
88 89
}

A
Alex Dima 已提交
90
function moveToBeginningOfBuffer(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
91 92 93
	cursorCommand(cursor, inSelectionMode ? H.CursorTopSelect : H.CursorTop);
}

A
Alex Dima 已提交
94
function moveToEndOfBuffer(cursor: Cursor, inSelectionMode: boolean = false) {
E
Erich Gamma 已提交
95 96 97
	cursorCommand(cursor, inSelectionMode ? H.CursorBottomSelect : H.CursorBottom);
}

A
Alex Dima 已提交
98
function deleteWordLeft(cursor: Cursor) {
E
Erich Gamma 已提交
99 100
	cursorCommand(cursor, H.DeleteWordLeft);
}
101 102 103 104 105 106
function deleteWordStartLeft(cursor: Cursor) {
	cursorCommand(cursor, H.DeleteWordStartLeft);
}
function deleteWordEndLeft(cursor: Cursor) {
	cursorCommand(cursor, H.DeleteWordEndLeft);
}
E
Erich Gamma 已提交
107

A
Alex Dima 已提交
108
function deleteWordRight(cursor: Cursor) {
E
Erich Gamma 已提交
109 110
	cursorCommand(cursor, H.DeleteWordRight);
}
111 112 113 114 115 116
function deleteWordStartRight(cursor: Cursor) {
	cursorCommand(cursor, H.DeleteWordStartRight);
}
function deleteWordEndRight(cursor: Cursor) {
	cursorCommand(cursor, H.DeleteWordEndRight);
}
E
Erich Gamma 已提交
117

J
Johannes Rieken 已提交
118 119
function assertCursor(cursor: Cursor, what: Position | Selection | Selection[]): void {
	let selections: Selection[];
A
Alex Dima 已提交
120 121 122 123 124 125 126
	if (what instanceof Position) {
		selections = [new Selection(what.lineNumber, what.column, what.lineNumber, what.column)];
	} else if (what instanceof Selection) {
		selections = [what];
	} else {
		selections = what;
	}
A
Alex Dima 已提交
127 128 129 130 131
	let actual = cursor.getSelections().map(s => s.toString());
	let expected = selections.map(s => s.toString());

	assert.deepEqual(actual, expected);
}
E
Erich Gamma 已提交
132 133

suite('Editor Controller - Cursor', () => {
A
Alex Dima 已提交
134 135 136 137 138
	const LINE1 = '    \tMy First Line\t ';
	const LINE2 = '\tMy Second Line';
	const LINE3 = '    Third Line💩';
	const LINE4 = '';
	const LINE5 = '1';
E
Erich Gamma 已提交
139

A
Alex Dima 已提交
140 141 142
	let thisModel: Model;
	let thisConfiguration: MockConfiguration;
	let thisCursor: Cursor;
E
Erich Gamma 已提交
143 144

	setup(() => {
A
Alex Dima 已提交
145
		let text =
E
Erich Gamma 已提交
146 147 148 149 150 151
			LINE1 + '\r\n' +
			LINE2 + '\n' +
			LINE3 + '\n' +
			LINE4 + '\r\n' +
			LINE5;

152
		thisModel = Model.createFromString(text);
E
Erich Gamma 已提交
153
		thisConfiguration = new MockConfiguration(null);
154
		thisCursor = new Cursor(1, thisConfiguration, thisModel, viewModelHelper(thisModel), false);
E
Erich Gamma 已提交
155 156 157 158 159 160 161 162 163
	});

	teardown(() => {
		thisCursor.dispose();
		thisModel.dispose();
		thisConfiguration.dispose();
	});

	test('cursor initialized', () => {
A
Alex Dima 已提交
164
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
165 166 167 168 169 170
	});

	// --------- absolute move

	test('no move', () => {
		moveTo(thisCursor, 1, 1);
A
Alex Dima 已提交
171
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
172 173 174 175
	});

	test('move', () => {
		moveTo(thisCursor, 1, 2);
A
Alex Dima 已提交
176
		assertCursor(thisCursor, new Position(1, 2));
E
Erich Gamma 已提交
177 178 179 180
	});

	test('move in selection mode', () => {
		moveTo(thisCursor, 1, 2, true);
A
Alex Dima 已提交
181
		assertCursor(thisCursor, new Selection(1, 1, 1, 2));
E
Erich Gamma 已提交
182 183 184 185
	});

	test('move beyond line end', () => {
		moveTo(thisCursor, 1, 25);
A
Alex Dima 已提交
186
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
187 188 189 190
	});

	test('move empty line', () => {
		moveTo(thisCursor, 4, 20);
A
Alex Dima 已提交
191
		assertCursor(thisCursor, new Position(4, 1));
E
Erich Gamma 已提交
192 193 194 195
	});

	test('move one char line', () => {
		moveTo(thisCursor, 5, 20);
A
Alex Dima 已提交
196
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
197 198 199 200
	});

	test('selection down', () => {
		moveTo(thisCursor, 2, 1, true);
A
Alex Dima 已提交
201
		assertCursor(thisCursor, new Selection(1, 1, 2, 1));
E
Erich Gamma 已提交
202 203 204 205
	});

	test('move and then select', () => {
		moveTo(thisCursor, 2, 3);
A
Alex Dima 已提交
206
		assertCursor(thisCursor, new Position(2, 3));
E
Erich Gamma 已提交
207 208

		moveTo(thisCursor, 2, 15, true);
A
Alex Dima 已提交
209
		assertCursor(thisCursor, new Selection(2, 3, 2, 15));
E
Erich Gamma 已提交
210 211

		moveTo(thisCursor, 1, 2, true);
A
Alex Dima 已提交
212
		assertCursor(thisCursor, new Selection(2, 3, 1, 2));
E
Erich Gamma 已提交
213 214 215 216 217 218
	});

	// --------- move left

	test('move left on top left position', () => {
		moveLeft(thisCursor);
A
Alex Dima 已提交
219
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
220 221 222 223
	});

	test('move left', () => {
		moveTo(thisCursor, 1, 3);
A
Alex Dima 已提交
224
		assertCursor(thisCursor, new Position(1, 3));
E
Erich Gamma 已提交
225
		moveLeft(thisCursor);
A
Alex Dima 已提交
226
		assertCursor(thisCursor, new Position(1, 2));
E
Erich Gamma 已提交
227 228
	});

229 230
	test('move left with surrogate pair', () => {
		moveTo(thisCursor, 3, 17);
A
Alex Dima 已提交
231
		assertCursor(thisCursor, new Position(3, 17));
232
		moveLeft(thisCursor);
A
Alex Dima 已提交
233
		assertCursor(thisCursor, new Position(3, 15));
234 235
	});

E
Erich Gamma 已提交
236 237
	test('move left goes to previous row', () => {
		moveTo(thisCursor, 2, 1);
A
Alex Dima 已提交
238
		assertCursor(thisCursor, new Position(2, 1));
E
Erich Gamma 已提交
239
		moveLeft(thisCursor);
A
Alex Dima 已提交
240
		assertCursor(thisCursor, new Position(1, 21));
E
Erich Gamma 已提交
241 242 243 244
	});

	test('move left selection', () => {
		moveTo(thisCursor, 2, 1);
A
Alex Dima 已提交
245
		assertCursor(thisCursor, new Position(2, 1));
E
Erich Gamma 已提交
246
		moveLeft(thisCursor, true);
A
Alex Dima 已提交
247
		assertCursor(thisCursor, new Selection(2, 1, 1, 21));
E
Erich Gamma 已提交
248 249 250 251 252 253
	});

	// --------- move word left

	test('move word left', () => {
		moveTo(thisCursor, 5, 2);
A
Alex Dima 已提交
254
		let expectedStops = [
E
Erich Gamma 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
			[5, 1],
			[4, 1],
			[3, 11],
			[3, 5],
			[3, 1],
			[2, 12],
			[2, 5],
			[2, 2],
			[2, 1],
			[1, 15],
			[1, 9],
			[1, 6],
			[1, 1],
			[1, 1],
		];

J
Johannes Rieken 已提交
271
		let actualStops: number[][] = [];
A
Alex Dima 已提交
272
		for (let i = 0; i < expectedStops.length; i++) {
E
Erich Gamma 已提交
273
			moveWordLeft(thisCursor);
A
Alex Dima 已提交
274
			let pos = thisCursor.getPosition();
E
Erich Gamma 已提交
275 276 277 278 279 280 281 282
			actualStops.push([pos.lineNumber, pos.column]);
		}

		assert.deepEqual(actualStops, expectedStops);
	});

	test('move word left selection', () => {
		moveTo(thisCursor, 5, 2);
A
Alex Dima 已提交
283
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
284
		moveWordLeft(thisCursor, true);
A
Alex Dima 已提交
285
		assertCursor(thisCursor, new Selection(5, 2, 5, 1));
E
Erich Gamma 已提交
286 287 288 289 290 291
	});

	// --------- move right

	test('move right on bottom right position', () => {
		moveTo(thisCursor, 5, 2);
A
Alex Dima 已提交
292
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
293
		moveRight(thisCursor);
A
Alex Dima 已提交
294
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
295 296 297 298
	});

	test('move right', () => {
		moveTo(thisCursor, 1, 3);
A
Alex Dima 已提交
299
		assertCursor(thisCursor, new Position(1, 3));
E
Erich Gamma 已提交
300
		moveRight(thisCursor);
A
Alex Dima 已提交
301
		assertCursor(thisCursor, new Position(1, 4));
E
Erich Gamma 已提交
302 303
	});

304 305
	test('move right with surrogate pair', () => {
		moveTo(thisCursor, 3, 15);
A
Alex Dima 已提交
306
		assertCursor(thisCursor, new Position(3, 15));
307
		moveRight(thisCursor);
A
Alex Dima 已提交
308
		assertCursor(thisCursor, new Position(3, 17));
309 310
	});

E
Erich Gamma 已提交
311 312
	test('move right goes to next row', () => {
		moveTo(thisCursor, 1, 21);
A
Alex Dima 已提交
313
		assertCursor(thisCursor, new Position(1, 21));
E
Erich Gamma 已提交
314
		moveRight(thisCursor);
A
Alex Dima 已提交
315
		assertCursor(thisCursor, new Position(2, 1));
E
Erich Gamma 已提交
316 317 318 319
	});

	test('move right selection', () => {
		moveTo(thisCursor, 1, 21);
A
Alex Dima 已提交
320
		assertCursor(thisCursor, new Position(1, 21));
E
Erich Gamma 已提交
321
		moveRight(thisCursor, true);
A
Alex Dima 已提交
322
		assertCursor(thisCursor, new Selection(1, 21, 2, 1));
E
Erich Gamma 已提交
323 324 325 326 327 328
	});

	// --------- move word right

	test('move word right', () => {
		moveTo(thisCursor, 1, 1);
A
Alex Dima 已提交
329
		let expectedStops = [
E
Erich Gamma 已提交
330 331 332 333 334 335 336 337
			[1, 8],
			[1, 14],
			[1, 19],
			[1, 21],
			[2, 4],
			[2, 11],
			[2, 16],
			[3, 10],
338
			[3, 17],
E
Erich Gamma 已提交
339 340 341 342 343
			[4, 1],
			[5, 2],
			[5, 2],
		];

J
Johannes Rieken 已提交
344
		let actualStops: number[][] = [];
A
Alex Dima 已提交
345
		for (let i = 0; i < expectedStops.length; i++) {
E
Erich Gamma 已提交
346
			moveWordRight(thisCursor);
A
Alex Dima 已提交
347
			let pos = thisCursor.getPosition();
E
Erich Gamma 已提交
348 349 350 351 352 353 354 355
			actualStops.push([pos.lineNumber, pos.column]);
		}

		assert.deepEqual(actualStops, expectedStops);
	});

	test('move word right selection', () => {
		moveTo(thisCursor, 1, 1);
A
Alex Dima 已提交
356
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
357
		moveWordRight(thisCursor, true);
A
Alex Dima 已提交
358
		assertCursor(thisCursor, new Selection(1, 1, 1, 8));
E
Erich Gamma 已提交
359 360 361 362 363
	});
	// --------- move down

	test('move down', () => {
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
364
		assertCursor(thisCursor, new Position(2, 1));
E
Erich Gamma 已提交
365
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
366
		assertCursor(thisCursor, new Position(3, 1));
E
Erich Gamma 已提交
367
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
368
		assertCursor(thisCursor, new Position(4, 1));
E
Erich Gamma 已提交
369
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
370
		assertCursor(thisCursor, new Position(5, 1));
E
Erich Gamma 已提交
371
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
372
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
373 374 375 376
	});

	test('move down with selection', () => {
		moveDown(thisCursor, 1, true);
A
Alex Dima 已提交
377
		assertCursor(thisCursor, new Selection(1, 1, 2, 1));
E
Erich Gamma 已提交
378
		moveDown(thisCursor, 1, true);
A
Alex Dima 已提交
379
		assertCursor(thisCursor, new Selection(1, 1, 3, 1));
E
Erich Gamma 已提交
380
		moveDown(thisCursor, 1, true);
A
Alex Dima 已提交
381
		assertCursor(thisCursor, new Selection(1, 1, 4, 1));
E
Erich Gamma 已提交
382
		moveDown(thisCursor, 1, true);
A
Alex Dima 已提交
383
		assertCursor(thisCursor, new Selection(1, 1, 5, 1));
E
Erich Gamma 已提交
384
		moveDown(thisCursor, 1, true);
A
Alex Dima 已提交
385
		assertCursor(thisCursor, new Selection(1, 1, 5, 2));
E
Erich Gamma 已提交
386 387 388 389
	});

	test('move down with tabs', () => {
		moveTo(thisCursor, 1, 5);
A
Alex Dima 已提交
390
		assertCursor(thisCursor, new Position(1, 5));
E
Erich Gamma 已提交
391
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
392
		assertCursor(thisCursor, new Position(2, 2));
E
Erich Gamma 已提交
393
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
394
		assertCursor(thisCursor, new Position(3, 5));
E
Erich Gamma 已提交
395
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
396
		assertCursor(thisCursor, new Position(4, 1));
E
Erich Gamma 已提交
397
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
398
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
399 400 401 402 403 404
	});

	// --------- move up

	test('move up', () => {
		moveTo(thisCursor, 3, 5);
A
Alex Dima 已提交
405
		assertCursor(thisCursor, new Position(3, 5));
E
Erich Gamma 已提交
406 407

		moveUp(thisCursor, 1);
A
Alex Dima 已提交
408
		assertCursor(thisCursor, new Position(2, 2));
E
Erich Gamma 已提交
409 410

		moveUp(thisCursor, 1);
A
Alex Dima 已提交
411
		assertCursor(thisCursor, new Position(1, 5));
E
Erich Gamma 已提交
412 413 414 415
	});

	test('move up with selection', () => {
		moveTo(thisCursor, 3, 5);
A
Alex Dima 已提交
416
		assertCursor(thisCursor, new Position(3, 5));
E
Erich Gamma 已提交
417 418

		moveUp(thisCursor, 1, true);
A
Alex Dima 已提交
419
		assertCursor(thisCursor, new Selection(3, 5, 2, 2));
E
Erich Gamma 已提交
420 421

		moveUp(thisCursor, 1, true);
A
Alex Dima 已提交
422
		assertCursor(thisCursor, new Selection(3, 5, 1, 5));
E
Erich Gamma 已提交
423 424 425 426
	});

	test('move up and down with tabs', () => {
		moveTo(thisCursor, 1, 5);
A
Alex Dima 已提交
427
		assertCursor(thisCursor, new Position(1, 5));
E
Erich Gamma 已提交
428
		moveDown(thisCursor, 4);
A
Alex Dima 已提交
429
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
430
		moveUp(thisCursor, 1);
A
Alex Dima 已提交
431
		assertCursor(thisCursor, new Position(4, 1));
E
Erich Gamma 已提交
432
		moveUp(thisCursor, 1);
A
Alex Dima 已提交
433
		assertCursor(thisCursor, new Position(3, 5));
E
Erich Gamma 已提交
434
		moveUp(thisCursor, 1);
A
Alex Dima 已提交
435
		assertCursor(thisCursor, new Position(2, 2));
E
Erich Gamma 已提交
436
		moveUp(thisCursor, 1);
A
Alex Dima 已提交
437
		assertCursor(thisCursor, new Position(1, 5));
E
Erich Gamma 已提交
438 439 440 441
	});

	test('move up and down with end of lines starting from a long one', () => {
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
442
		assertCursor(thisCursor, new Position(1, LINE1.length - 1));
E
Erich Gamma 已提交
443
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
444
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
445
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
446
		assertCursor(thisCursor, new Position(2, LINE2.length + 1));
E
Erich Gamma 已提交
447
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
448
		assertCursor(thisCursor, new Position(3, LINE3.length + 1));
E
Erich Gamma 已提交
449
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
450
		assertCursor(thisCursor, new Position(4, LINE4.length + 1));
E
Erich Gamma 已提交
451
		moveDown(thisCursor, 1);
A
Alex Dima 已提交
452
		assertCursor(thisCursor, new Position(5, LINE5.length + 1));
E
Erich Gamma 已提交
453
		moveUp(thisCursor, 4);
A
Alex Dima 已提交
454
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
455 456 457 458 459 460
	});

	// --------- move to beginning of line

	test('move to beginning of line', () => {
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
461
		assertCursor(thisCursor, new Position(1, 6));
E
Erich Gamma 已提交
462
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
463
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
464 465 466 467 468
	});

	test('move to beginning of line from within line', () => {
		moveTo(thisCursor, 1, 8);
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
469
		assertCursor(thisCursor, new Position(1, 6));
E
Erich Gamma 已提交
470
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
471
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
472 473 474 475 476
	});

	test('move to beginning of line from whitespace at beginning of line', () => {
		moveTo(thisCursor, 1, 2);
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
477
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
478
		moveToBeginningOfLine(thisCursor);
A
Alex Dima 已提交
479
		assertCursor(thisCursor, new Position(1, 6));
E
Erich Gamma 已提交
480 481 482 483 484
	});

	test('move to beginning of line from within line selection', () => {
		moveTo(thisCursor, 1, 8);
		moveToBeginningOfLine(thisCursor, true);
A
Alex Dima 已提交
485
		assertCursor(thisCursor, new Selection(1, 8, 1, 6));
E
Erich Gamma 已提交
486
		moveToBeginningOfLine(thisCursor, true);
A
Alex Dima 已提交
487
		assertCursor(thisCursor, new Selection(1, 8, 1, 1));
E
Erich Gamma 已提交
488 489 490 491 492 493
	});

	// --------- move to end of line

	test('move to end of line', () => {
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
494
		assertCursor(thisCursor, new Position(1, LINE1.length - 1));
E
Erich Gamma 已提交
495
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
496
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
497 498 499 500 501
	});

	test('move to end of line from within line', () => {
		moveTo(thisCursor, 1, 6);
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
502
		assertCursor(thisCursor, new Position(1, LINE1.length - 1));
E
Erich Gamma 已提交
503
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
504
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
505 506 507 508 509
	});

	test('move to end of line from whitespace at end of line', () => {
		moveTo(thisCursor, 1, 20);
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
510
		assertCursor(thisCursor, new Position(1, LINE1.length + 1));
E
Erich Gamma 已提交
511
		moveToEndOfLine(thisCursor);
A
Alex Dima 已提交
512
		assertCursor(thisCursor, new Position(1, LINE1.length - 1));
E
Erich Gamma 已提交
513 514 515 516 517
	});

	test('move to end of line from within line selection', () => {
		moveTo(thisCursor, 1, 6);
		moveToEndOfLine(thisCursor, true);
A
Alex Dima 已提交
518
		assertCursor(thisCursor, new Selection(1, 6, 1, LINE1.length - 1));
E
Erich Gamma 已提交
519
		moveToEndOfLine(thisCursor, true);
A
Alex Dima 已提交
520
		assertCursor(thisCursor, new Selection(1, 6, 1, LINE1.length + 1));
E
Erich Gamma 已提交
521 522 523 524 525 526
	});

	// --------- move to beginning of buffer

	test('move to beginning of buffer', () => {
		moveToBeginningOfBuffer(thisCursor);
A
Alex Dima 已提交
527
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
528 529 530 531 532
	});

	test('move to beginning of buffer from within first line', () => {
		moveTo(thisCursor, 1, 3);
		moveToBeginningOfBuffer(thisCursor);
A
Alex Dima 已提交
533
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
534 535 536 537 538
	});

	test('move to beginning of buffer from within another line', () => {
		moveTo(thisCursor, 3, 3);
		moveToBeginningOfBuffer(thisCursor);
A
Alex Dima 已提交
539
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
540 541 542 543 544
	});

	test('move to beginning of buffer from within first line selection', () => {
		moveTo(thisCursor, 1, 3);
		moveToBeginningOfBuffer(thisCursor, true);
A
Alex Dima 已提交
545
		assertCursor(thisCursor, new Selection(1, 3, 1, 1));
E
Erich Gamma 已提交
546 547 548 549 550
	});

	test('move to beginning of buffer from within another line selection', () => {
		moveTo(thisCursor, 3, 3);
		moveToBeginningOfBuffer(thisCursor, true);
A
Alex Dima 已提交
551
		assertCursor(thisCursor, new Selection(3, 3, 1, 1));
E
Erich Gamma 已提交
552 553 554 555 556 557
	});

	// --------- move to end of buffer

	test('move to end of buffer', () => {
		moveToEndOfBuffer(thisCursor);
A
Alex Dima 已提交
558
		assertCursor(thisCursor, new Position(5, LINE5.length + 1));
E
Erich Gamma 已提交
559 560 561 562 563
	});

	test('move to end of buffer from within last line', () => {
		moveTo(thisCursor, 5, 1);
		moveToEndOfBuffer(thisCursor);
A
Alex Dima 已提交
564
		assertCursor(thisCursor, new Position(5, LINE5.length + 1));
E
Erich Gamma 已提交
565 566 567 568 569
	});

	test('move to end of buffer from within another line', () => {
		moveTo(thisCursor, 3, 3);
		moveToEndOfBuffer(thisCursor);
A
Alex Dima 已提交
570
		assertCursor(thisCursor, new Position(5, LINE5.length + 1));
E
Erich Gamma 已提交
571 572 573 574 575
	});

	test('move to end of buffer from within last line selection', () => {
		moveTo(thisCursor, 5, 1);
		moveToEndOfBuffer(thisCursor, true);
A
Alex Dima 已提交
576
		assertCursor(thisCursor, new Selection(5, 1, 5, LINE5.length + 1));
E
Erich Gamma 已提交
577 578 579 580 581
	});

	test('move to end of buffer from within another line selection', () => {
		moveTo(thisCursor, 3, 3);
		moveToEndOfBuffer(thisCursor, true);
A
Alex Dima 已提交
582
		assertCursor(thisCursor, new Selection(3, 3, 5, LINE5.length + 1));
E
Erich Gamma 已提交
583 584 585 586 587 588 589 590 591
	});

	// --------- delete word left/right

	test('delete word left for non-empty selection', () => {
		moveTo(thisCursor, 3, 7);
		moveRight(thisCursor, true);
		moveRight(thisCursor, true);
		deleteWordLeft(thisCursor);
592
		assert.equal(thisModel.getLineContent(3), '    Thd Line💩');
A
Alex Dima 已提交
593
		assertCursor(thisCursor, new Position(3, 7));
E
Erich Gamma 已提交
594 595 596 597 598 599
	});

	test('delete word left for caret at beginning of document', () => {
		moveTo(thisCursor, 1, 1);
		deleteWordLeft(thisCursor);
		assert.equal(thisModel.getLineContent(1), '    \tMy First Line\t ');
A
Alex Dima 已提交
600
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
601 602 603 604 605
	});

	test('delete word left for caret at end of whitespace', () => {
		moveTo(thisCursor, 3, 11);
		deleteWordLeft(thisCursor);
606
		assert.equal(thisModel.getLineContent(3), '    Line💩');
A
Alex Dima 已提交
607
		assertCursor(thisCursor, new Position(3, 5));
E
Erich Gamma 已提交
608 609 610 611 612 613
	});

	test('delete word left for caret just behind a word', () => {
		moveTo(thisCursor, 2, 11);
		deleteWordLeft(thisCursor);
		assert.equal(thisModel.getLineContent(2), '\tMy  Line');
A
Alex Dima 已提交
614
		assertCursor(thisCursor, new Position(2, 5));
E
Erich Gamma 已提交
615 616 617 618 619 620
	});

	test('delete word left for caret inside of a word', () => {
		moveTo(thisCursor, 1, 12);
		deleteWordLeft(thisCursor);
		assert.equal(thisModel.getLineContent(1), '    \tMy st Line\t ');
A
Alex Dima 已提交
621
		assertCursor(thisCursor, new Position(1, 9));
E
Erich Gamma 已提交
622 623 624 625 626 627 628
	});

	test('delete word right for non-empty selection', () => {
		moveTo(thisCursor, 3, 7);
		moveRight(thisCursor, true);
		moveRight(thisCursor, true);
		deleteWordRight(thisCursor);
629
		assert.equal(thisModel.getLineContent(3), '    Thd Line💩');
A
Alex Dima 已提交
630
		assertCursor(thisCursor, new Position(3, 7));
E
Erich Gamma 已提交
631 632 633 634 635 636
	});

	test('delete word right for caret at end of document', () => {
		moveTo(thisCursor, 5, 3);
		deleteWordRight(thisCursor);
		assert.equal(thisModel.getLineContent(5), '1');
A
Alex Dima 已提交
637
		assertCursor(thisCursor, new Position(5, 2));
E
Erich Gamma 已提交
638 639 640 641 642
	});

	test('delete word right for caret at beggining of whitespace', () => {
		moveTo(thisCursor, 3, 1);
		deleteWordRight(thisCursor);
643
		assert.equal(thisModel.getLineContent(3), 'Third Line💩');
A
Alex Dima 已提交
644
		assertCursor(thisCursor, new Position(3, 1));
E
Erich Gamma 已提交
645 646 647 648 649 650
	});

	test('delete word right for caret just before a word', () => {
		moveTo(thisCursor, 2, 5);
		deleteWordRight(thisCursor);
		assert.equal(thisModel.getLineContent(2), '\tMy  Line');
A
Alex Dima 已提交
651
		assertCursor(thisCursor, new Position(2, 5));
E
Erich Gamma 已提交
652 653 654 655 656 657
	});

	test('delete word right for caret inside of a word', () => {
		moveTo(thisCursor, 1, 11);
		deleteWordRight(thisCursor);
		assert.equal(thisModel.getLineContent(1), '    \tMy Fi Line\t ');
A
Alex Dima 已提交
658
		assertCursor(thisCursor, new Position(1, 11));
E
Erich Gamma 已提交
659 660 661 662 663 664
	});

	// --------- misc

	test('select all', () => {
		cursorCommand(thisCursor, H.SelectAll);
A
Alex Dima 已提交
665
		assertCursor(thisCursor, new Selection(1, 1, 5, LINE5.length + 1));
E
Erich Gamma 已提交
666 667
	});

A
Alex Dima 已提交
668 669 670
	test('expandLineSelection', () => {
		//              0          1         2
		//              01234 56789012345678 0
A
Alex Dima 已提交
671
		// let LINE1 = '    \tMy First Line\t ';
A
Alex Dima 已提交
672 673
		moveTo(thisCursor, 1, 1);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
674
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
675 676 677

		moveTo(thisCursor, 1, 2);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
678
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
679 680 681

		moveTo(thisCursor, 1, 5);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
682
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
683 684 685

		moveTo(thisCursor, 1, 19);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
686
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
687 688 689

		moveTo(thisCursor, 1, 20);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
690
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
691 692 693

		moveTo(thisCursor, 1, 21);
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
694
		assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1));
A
Alex Dima 已提交
695
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
696
		assertCursor(thisCursor, new Selection(1, 1, 2, LINE2.length + 1));
A
Alex Dima 已提交
697
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
698
		assertCursor(thisCursor, new Selection(1, 1, 3, LINE3.length + 1));
A
Alex Dima 已提交
699
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
700
		assertCursor(thisCursor, new Selection(1, 1, 4, LINE4.length + 1));
A
Alex Dima 已提交
701
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
702
		assertCursor(thisCursor, new Selection(1, 1, 5, LINE5.length + 1));
A
Alex Dima 已提交
703
		cursorCommand(thisCursor, H.ExpandLineSelection);
A
Alex Dima 已提交
704
		assertCursor(thisCursor, new Selection(1, 1, 5, LINE5.length + 1));
A
Alex Dima 已提交
705 706
	});

E
Erich Gamma 已提交
707 708 709
	// --------- eventing

	test('no move doesn\'t trigger event', () => {
A
Alex Dima 已提交
710
		thisCursor.addListener2(EventType.CursorPositionChanged, (e) => {
E
Erich Gamma 已提交
711 712
			assert.ok(false, 'was not expecting event');
		});
A
Alex Dima 已提交
713
		thisCursor.addListener2(EventType.CursorSelectionChanged, (e) => {
E
Erich Gamma 已提交
714 715 716 717 718 719
			assert.ok(false, 'was not expecting event');
		});
		moveTo(thisCursor, 1, 1);
	});

	test('move eventing', () => {
A
Alex Dima 已提交
720
		let events = 0;
J
Johannes Rieken 已提交
721
		thisCursor.addListener2(EventType.CursorPositionChanged, (e: ICursorPositionChangedEvent) => {
E
Erich Gamma 已提交
722
			events++;
A
Alex Dima 已提交
723
			assert.deepEqual(e.position, new Position(1, 2));
E
Erich Gamma 已提交
724
		});
J
Johannes Rieken 已提交
725
		thisCursor.addListener2(EventType.CursorSelectionChanged, (e: ICursorSelectionChangedEvent) => {
E
Erich Gamma 已提交
726
			events++;
A
Alex Dima 已提交
727
			assert.deepEqual(e.selection, new Selection(1, 2, 1, 2));
E
Erich Gamma 已提交
728 729 730 731 732 733
		});
		moveTo(thisCursor, 1, 2);
		assert.equal(events, 2, 'receives 2 events');
	});

	test('move in selection mode eventing', () => {
A
Alex Dima 已提交
734
		let events = 0;
J
Johannes Rieken 已提交
735
		thisCursor.addListener2(EventType.CursorPositionChanged, (e: ICursorPositionChangedEvent) => {
E
Erich Gamma 已提交
736
			events++;
A
Alex Dima 已提交
737
			assert.deepEqual(e.position, new Position(1, 2));
E
Erich Gamma 已提交
738
		});
J
Johannes Rieken 已提交
739
		thisCursor.addListener2(EventType.CursorSelectionChanged, (e: ICursorSelectionChangedEvent) => {
E
Erich Gamma 已提交
740
			events++;
741
			assert.deepEqual(e.selection, new Selection(1, 1, 1, 2));
E
Erich Gamma 已提交
742 743 744 745 746 747 748 749 750
		});
		moveTo(thisCursor, 1, 2, true);
		assert.equal(events, 2, 'receives 2 events');
	});

	// --------- state save & restore

	test('saveState & restoreState', () => {
		moveTo(thisCursor, 2, 1, true);
A
Alex Dima 已提交
751
		assertCursor(thisCursor, new Selection(1, 1, 2, 1));
E
Erich Gamma 已提交
752

A
Alex Dima 已提交
753
		let savedState = JSON.stringify(thisCursor.saveState());
E
Erich Gamma 已提交
754 755

		moveTo(thisCursor, 1, 1, false);
A
Alex Dima 已提交
756
		assertCursor(thisCursor, new Position(1, 1));
E
Erich Gamma 已提交
757 758

		thisCursor.restoreState(JSON.parse(savedState));
A
Alex Dima 已提交
759
		assertCursor(thisCursor, new Selection(1, 1, 2, 1));
E
Erich Gamma 已提交
760 761 762 763 764 765 766
	});

	// --------- updating cursor

	test('Independent model edit 1', () => {
		moveTo(thisCursor, 2, 16, true);

A
Alex Dima 已提交
767
		thisModel.applyEdits([EditOperation.delete(new Range(2, 1, 2, 2))]);
A
Alex Dima 已提交
768
		assertCursor(thisCursor, new Selection(1, 1, 2, 15));
E
Erich Gamma 已提交
769
	});
A
Alex Dima 已提交
770 771

	test('column select 1', () => {
772
		let model = Model.createFromString([
A
Alex Dima 已提交
773 774 775 776 777
			'\tprivate compute(a:number): boolean {',
			'\t\tif (a + 3 === 0 || a + 5 === 0) {',
			'\t\t\treturn false;',
			'\t\t}',
			'\t}'
778
		].join('\n'));
779
		let cursor = new Cursor(1, new MockConfiguration(null), model, viewModelHelper(model), true);
A
Alex Dima 已提交
780 781

		moveTo(cursor, 1, 7, false);
A
Alex Dima 已提交
782
		assertCursor(cursor, new Position(1, 7));
A
Alex Dima 已提交
783 784 785 786 787 788 789 790

		cursorCommand(cursor, H.ColumnSelect, {
			position: new Position(4, 4),
			viewPosition: new Position(4, 4),
			mouseColumn: 15
		});

		let expectedSelections = [
A
Alex Dima 已提交
791 792 793
			new Selection(1, 7, 1, 12),
			new Selection(2, 4, 2, 9),
			new Selection(3, 3, 3, 6),
A
Alex Dima 已提交
794 795 796
			new Selection(4, 4, 4, 4),
		];

A
Alex Dima 已提交
797
		assertCursor(cursor, expectedSelections);
A
Alex Dima 已提交
798 799 800 801

		cursor.dispose();
		model.dispose();
	});
A
Alex Dima 已提交
802 803

	test('issue #4905 - column select is biased to the right', () => {
804
		let model = Model.createFromString([
A
Alex Dima 已提交
805 806 807 808 809 810 811
			'var gulp = require("gulp");',
			'var path = require("path");',
			'var rimraf = require("rimraf");',
			'var isarray = require("isarray");',
			'var merge = require("merge-stream");',
			'var concat = require("gulp-concat");',
			'var newer = require("gulp-newer");',
812
		].join('\n'));
813
		let cursor = new Cursor(1, new MockConfiguration(null), model, viewModelHelper(model), true);
A
Alex Dima 已提交
814 815

		moveTo(cursor, 1, 4, false);
A
Alex Dima 已提交
816
		assertCursor(cursor, new Position(1, 4));
A
Alex Dima 已提交
817 818 819 820 821 822 823

		cursorCommand(cursor, H.ColumnSelect, {
			position: new Position(4, 1),
			viewPosition: new Position(4, 1),
			mouseColumn: 1
		});

A
Alex Dima 已提交
824
		assertCursor(cursor, [
A
Alex Dima 已提交
825 826 827 828 829 830 831 832 833 834 835
			new Selection(1, 4, 1, 1),
			new Selection(2, 4, 2, 1),
			new Selection(3, 4, 3, 1),
			new Selection(4, 4, 4, 1),
		]);

		cursor.dispose();
		model.dispose();
	});

	test('column select with keyboard', () => {
836
		let model = Model.createFromString([
A
Alex Dima 已提交
837 838 839 840 841 842 843
			'var gulp = require("gulp");',
			'var path = require("path");',
			'var rimraf = require("rimraf");',
			'var isarray = require("isarray");',
			'var merge = require("merge-stream");',
			'var concat = require("gulp-concat");',
			'var newer = require("gulp-newer");',
844
		].join('\n'));
845
		let cursor = new Cursor(1, new MockConfiguration(null), model, viewModelHelper(model), true);
A
Alex Dima 已提交
846 847

		moveTo(cursor, 1, 4, false);
A
Alex Dima 已提交
848
		assertCursor(cursor, new Position(1, 4));
A
Alex Dima 已提交
849 850

		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
851
		assertCursor(cursor, [
A
Alex Dima 已提交
852 853 854 855
			new Selection(1, 4, 1, 5)
		]);

		cursorCommand(cursor, H.CursorColumnSelectDown);
A
Alex Dima 已提交
856
		assertCursor(cursor, [
A
Alex Dima 已提交
857 858 859 860 861
			new Selection(1, 4, 1, 5),
			new Selection(2, 4, 2, 5)
		]);

		cursorCommand(cursor, H.CursorColumnSelectDown);
A
Alex Dima 已提交
862
		assertCursor(cursor, [
A
Alex Dima 已提交
863 864 865 866 867 868 869 870 871
			new Selection(1, 4, 1, 5),
			new Selection(2, 4, 2, 5),
			new Selection(3, 4, 3, 5),
		]);

		cursorCommand(cursor, H.CursorColumnSelectDown);
		cursorCommand(cursor, H.CursorColumnSelectDown);
		cursorCommand(cursor, H.CursorColumnSelectDown);
		cursorCommand(cursor, H.CursorColumnSelectDown);
A
Alex Dima 已提交
872
		assertCursor(cursor, [
A
Alex Dima 已提交
873 874 875 876 877 878 879 880 881 882
			new Selection(1, 4, 1, 5),
			new Selection(2, 4, 2, 5),
			new Selection(3, 4, 3, 5),
			new Selection(4, 4, 4, 5),
			new Selection(5, 4, 5, 5),
			new Selection(6, 4, 6, 5),
			new Selection(7, 4, 7, 5),
		]);

		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
883
		assertCursor(cursor, [
A
Alex Dima 已提交
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
			new Selection(1, 4, 1, 6),
			new Selection(2, 4, 2, 6),
			new Selection(3, 4, 3, 6),
			new Selection(4, 4, 4, 6),
			new Selection(5, 4, 5, 6),
			new Selection(6, 4, 6, 6),
			new Selection(7, 4, 7, 6),
		]);

		// 10 times
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
904
		assertCursor(cursor, [
A
Alex Dima 已提交
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
			new Selection(1, 4, 1, 16),
			new Selection(2, 4, 2, 16),
			new Selection(3, 4, 3, 16),
			new Selection(4, 4, 4, 16),
			new Selection(5, 4, 5, 16),
			new Selection(6, 4, 6, 16),
			new Selection(7, 4, 7, 16),
		]);

		// 10 times
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
925
		assertCursor(cursor, [
A
Alex Dima 已提交
926 927 928 929 930 931 932 933 934 935 936 937
			new Selection(1, 4, 1, 26),
			new Selection(2, 4, 2, 26),
			new Selection(3, 4, 3, 26),
			new Selection(4, 4, 4, 26),
			new Selection(5, 4, 5, 26),
			new Selection(6, 4, 6, 26),
			new Selection(7, 4, 7, 26),
		]);

		// 2 times => reaching the ending of lines 1 and 2
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
938
		assertCursor(cursor, [
A
Alex Dima 已提交
939 940 941 942 943 944 945 946 947 948 949 950 951 952
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 28),
			new Selection(4, 4, 4, 28),
			new Selection(5, 4, 5, 28),
			new Selection(6, 4, 6, 28),
			new Selection(7, 4, 7, 28),
		]);

		// 4 times => reaching the ending of line 3
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
953
		assertCursor(cursor, [
A
Alex Dima 已提交
954 955 956 957 958 959 960 961 962 963 964 965
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 32),
			new Selection(5, 4, 5, 32),
			new Selection(6, 4, 6, 32),
			new Selection(7, 4, 7, 32),
		]);

		// 2 times => reaching the ending of line 4
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
966
		assertCursor(cursor, [
A
Alex Dima 已提交
967 968 969 970 971 972 973 974 975 976 977
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 34),
			new Selection(6, 4, 6, 34),
			new Selection(7, 4, 7, 34),
		]);

		// 1 time => reaching the ending of line 7
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
978
		assertCursor(cursor, [
A
Alex Dima 已提交
979 980 981 982 983 984 985 986 987 988 989 990 991
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 35),
			new Selection(6, 4, 6, 35),
			new Selection(7, 4, 7, 35),
		]);

		// 3 times => reaching the ending of lines 5 & 6
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
992
		assertCursor(cursor, [
A
Alex Dima 已提交
993 994 995 996 997 998 999 1000 1001 1002 1003
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 37),
			new Selection(6, 4, 6, 37),
			new Selection(7, 4, 7, 35),
		]);

		// cannot go anywhere anymore
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
1004
		assertCursor(cursor, [
A
Alex Dima 已提交
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 37),
			new Selection(6, 4, 6, 37),
			new Selection(7, 4, 7, 35),
		]);

		// cannot go anywhere anymore even if we insist
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
		cursorCommand(cursor, H.CursorColumnSelectRight);
A
Alex Dima 已提交
1019
		assertCursor(cursor, [
A
Alex Dima 已提交
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 37),
			new Selection(6, 4, 6, 37),
			new Selection(7, 4, 7, 35),
		]);

		// can easily go back
		cursorCommand(cursor, H.CursorColumnSelectLeft);
A
Alex Dima 已提交
1031
		assertCursor(cursor, [
A
Alex Dima 已提交
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
			new Selection(1, 4, 1, 28),
			new Selection(2, 4, 2, 28),
			new Selection(3, 4, 3, 32),
			new Selection(4, 4, 4, 34),
			new Selection(5, 4, 5, 36),
			new Selection(6, 4, 6, 36),
			new Selection(7, 4, 7, 35),
		]);

		cursor.dispose();
		model.dispose();
	});
1044 1045
});

1046
class SurroundingMode extends MockMode {
1047 1048
	constructor() {
		super();
1049
		LanguageConfigurationRegistry.register(this.getId(), {
1050
			autoClosingPairs: [{ open: '(', close: ')' }]
1051 1052 1053 1054
		});
	}
}

1055
class OnEnterMode extends MockMode {
A
Alex Dima 已提交
1056
	constructor(indentAction: IndentAction) {
1057
		super();
1058 1059 1060 1061 1062
		LanguageConfigurationRegistry.register(this.getId(), {
			onEnterRules: [{
				beforeText: /.*/,
				action: {
					indentAction: indentAction
1063
				}
1064 1065
			}]
		});
1066 1067 1068 1069
	}
}

suite('Editor Controller - Regression tests', () => {
E
Erich Gamma 已提交
1070
	test('Bug 9121: Auto indent + undo + redo is funky', () => {
A
Alex Dima 已提交
1071 1072 1073 1074
		usingCursor({
			text: [
				''
			],
1075 1076 1077 1078
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
1079 1080
				tabSize: 4,
				trimAutoWhitespace: false
1081
			}
A
Alex Dima 已提交
1082
		}, (model, cursor) => {
1083
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
A
Alex Dima 已提交
1084
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n', 'assert1');
E
Erich Gamma 已提交
1085

A
Alex Dima 已提交
1086 1087
			cursorCommand(cursor, H.Tab, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t', 'assert2');
E
Erich Gamma 已提交
1088

J
Johannes Rieken 已提交
1089
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
A
Alex Dima 已提交
1090
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\n\t', 'assert3');
E
Erich Gamma 已提交
1091

A
Alex Dima 已提交
1092 1093
			cursorCommand(cursor, H.Type, { text: 'x' });
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\n\tx', 'assert4');
E
Erich Gamma 已提交
1094

A
Alex Dima 已提交
1095 1096
			cursorCommand(cursor, H.CursorLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\n\tx', 'assert5');
E
Erich Gamma 已提交
1097

A
Alex Dima 已提交
1098 1099
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\nx', 'assert6');
E
Erich Gamma 已提交
1100

A
Alex Dima 已提交
1101 1102
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\tx', 'assert7');
E
Erich Gamma 已提交
1103

A
Alex Dima 已提交
1104 1105
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert8');
E
Erich Gamma 已提交
1106

A
Alex Dima 已提交
1107 1108
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), 'x', 'assert9');
E
Erich Gamma 已提交
1109

A
Alex Dima 已提交
1110 1111
			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert10');
E
Erich Gamma 已提交
1112

A
Alex Dima 已提交
1113 1114
			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\nx', 'assert11');
E
Erich Gamma 已提交
1115

A
Alex Dima 已提交
1116 1117
			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\n\tx', 'assert12');
E
Erich Gamma 已提交
1118

A
Alex Dima 已提交
1119 1120
			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t\nx', 'assert13');
E
Erich Gamma 已提交
1121

A
Alex Dima 已提交
1122 1123
			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert14');
E
Erich Gamma 已提交
1124

A
Alex Dima 已提交
1125 1126 1127
			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), 'x', 'assert15');
		});
E
Erich Gamma 已提交
1128
	});
1129

A
Alex Dima 已提交
1130
	test('issue #183: jump to matching bracket position', () => {
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
		class BracketMode extends MockMode {
			constructor() {
				super();
				LanguageConfigurationRegistry.register(this.getId(), {
					brackets: [
						['{', '}'],
						['[', ']'],
						['(', ')'],
					]
				});
			}
		}

A
Alex Dima 已提交
1144 1145 1146 1147
		usingCursor({
			text: [
				'var x = (3 + (5-7));'
			],
1148
			modeId: new BracketMode().getId()
A
Alex Dima 已提交
1149 1150 1151 1152 1153 1154
		}, (model, cursor) => {
			// ensure is tokenized
			model.getLineContext(1);

			moveTo(cursor, 1, 20);

1155
			cursorCommand(cursor, H.JumpToBracket, null, 'keyboard');
A
Alex Dima 已提交
1156
			assertCursor(cursor, new Position(1, 10));
A
Alex Dima 已提交
1157

1158
			cursorCommand(cursor, H.JumpToBracket, null, 'keyboard');
A
Alex Dima 已提交
1159
			assertCursor(cursor, new Position(1, 20));
A
Alex Dima 已提交
1160

1161
			cursorCommand(cursor, H.JumpToBracket, null, 'keyboard');
A
Alex Dima 已提交
1162
			assertCursor(cursor, new Position(1, 10));
A
Alex Dima 已提交
1163
		});
1164 1165
	});

E
Erich Gamma 已提交
1166
	test('bug #16543: Tab should indent to correct indentation spot immediately', () => {
A
Alex Dima 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175
		usingCursor({
			text: [
				'function baz() {',
				'\tfunction hello() { // something here',
				'\t',
				'',
				'\t}',
				'}'
			],
1176 1177 1178 1179
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
1180 1181
				tabSize: 4,
				trimAutoWhitespace: true
1182
			},
1183
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
A
Alex Dima 已提交
1184 1185
		}, (model, cursor) => {
			moveTo(cursor, 4, 1, false);
A
Alex Dima 已提交
1186
			assertCursor(cursor, new Selection(4, 1, 4, 1));
E
Erich Gamma 已提交
1187

1188
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
1189 1190
			assert.equal(model.getLineContent(4), '\t\t');
		});
E
Erich Gamma 已提交
1191 1192
	});

1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
	test('bug #2938 (1): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)', () => {
		usingCursor({
			text: [
				'\tfunction baz() {',
				'\t\tfunction hello() { // something here',
				'\t\t',
				'\t',
				'\t\t}',
				'\t}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
1210
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
1211 1212
		}, (model, cursor) => {
			moveTo(cursor, 4, 2, false);
A
Alex Dima 已提交
1213
			assertCursor(cursor, new Selection(4, 2, 4, 2));
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237

			cursorCommand(cursor, H.Tab, null, 'keyboard');
			assert.equal(model.getLineContent(4), '\t\t\t');
		});
	});


	test('bug #2938 (2): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)', () => {
		usingCursor({
			text: [
				'\tfunction baz() {',
				'\t\tfunction hello() { // something here',
				'\t\t',
				'    ',
				'\t\t}',
				'\t}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
1238
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
1239 1240
		}, (model, cursor) => {
			moveTo(cursor, 4, 1, false);
A
Alex Dima 已提交
1241
			assertCursor(cursor, new Selection(4, 1, 4, 1));
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264

			cursorCommand(cursor, H.Tab, null, 'keyboard');
			assert.equal(model.getLineContent(4), '\t\t\t');
		});
	});

	test('bug #2938 (3): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)', () => {
		usingCursor({
			text: [
				'\tfunction baz() {',
				'\t\tfunction hello() { // something here',
				'\t\t',
				'\t\t\t',
				'\t\t}',
				'\t}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
1265
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
1266 1267
		}, (model, cursor) => {
			moveTo(cursor, 4, 3, false);
A
Alex Dima 已提交
1268
			assertCursor(cursor, new Selection(4, 3, 4, 3));
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291

			cursorCommand(cursor, H.Tab, null, 'keyboard');
			assert.equal(model.getLineContent(4), '\t\t\t\t');
		});
	});

	test('bug #2938 (4): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)', () => {
		usingCursor({
			text: [
				'\tfunction baz() {',
				'\t\tfunction hello() { // something here',
				'\t\t',
				'\t\t\t\t',
				'\t\t}',
				'\t}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
1292
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
1293 1294
		}, (model, cursor) => {
			moveTo(cursor, 4, 4, false);
A
Alex Dima 已提交
1295
			assertCursor(cursor, new Selection(4, 4, 4, 4));
1296 1297 1298 1299 1300 1301

			cursorCommand(cursor, H.Tab, null, 'keyboard');
			assert.equal(model.getLineContent(4), '\t\t\t\t\t');
		});
	});

E
Erich Gamma 已提交
1302
	test('Bug 18276:[editor] Indentation broken when selection is empty', () => {
A
Alex Dima 已提交
1303 1304 1305 1306
		usingCursor({
			text: [
				'function baz() {'
			],
1307 1308 1309 1310
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
1311 1312
				tabSize: 4,
				trimAutoWhitespace: true
1313
			},
A
Alex Dima 已提交
1314 1315
		}, (model, cursor) => {
			moveTo(cursor, 1, 2, false);
A
Alex Dima 已提交
1316
			assertCursor(cursor, new Selection(1, 2, 1, 2));
A
Alex Dima 已提交
1317

1318
			cursorCommand(cursor, H.Indent, null, 'keyboard');
A
Alex Dima 已提交
1319 1320
			assert.equal(model.getLineContent(1), '\tfunction baz() {');

A
Alex Dima 已提交
1321
			assertCursor(cursor, new Selection(1, 3, 1, 3));
1322
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
1323 1324
			assert.equal(model.getLineContent(1), '\tf\tunction baz() {');
		});
E
Erich Gamma 已提交
1325 1326 1327
	});

	test('bug #16815:Shift+Tab doesn\'t go back to tabstop', () => {
A
Alex Dima 已提交
1328 1329 1330 1331
		usingCursor({
			text: [
				'     function baz() {'
			],
1332
			modeId: new OnEnterMode(IndentAction.IndentOutdent).getId(),
1333
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
1334 1335
		}, (model, cursor) => {
			moveTo(cursor, 1, 6, false);
A
Alex Dima 已提交
1336
			assertCursor(cursor, new Selection(1, 6, 1, 6));
A
Alex Dima 已提交
1337

1338
			cursorCommand(cursor, H.Outdent, null, 'keyboard');
A
Alex Dima 已提交
1339
			assert.equal(model.getLineContent(1), '    function baz() {');
A
Alex Dima 已提交
1340
			assertCursor(cursor, new Selection(1, 5, 1, 5));
A
Alex Dima 已提交
1341
		});
E
Erich Gamma 已提交
1342 1343 1344
	});

	test('Bug #18293:[regression][editor] Can\'t outdent whitespace line', () => {
A
Alex Dima 已提交
1345 1346 1347 1348
		usingCursor({
			text: [
				'      '
			],
1349
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
1350 1351
		}, (model, cursor) => {
			moveTo(cursor, 1, 7, false);
A
Alex Dima 已提交
1352
			assertCursor(cursor, new Selection(1, 7, 1, 7));
A
Alex Dima 已提交
1353

1354
			cursorCommand(cursor, H.Outdent, null, 'keyboard');
A
Alex Dima 已提交
1355
			assert.equal(model.getLineContent(1), '    ');
A
Alex Dima 已提交
1356
			assertCursor(cursor, new Selection(1, 5, 1, 5));
A
Alex Dima 已提交
1357
		});
E
Erich Gamma 已提交
1358 1359 1360
	});

	test('Bug #16657: [editor] Tab on empty line of zero indentation moves cursor to position (1,1)', () => {
A
Alex Dima 已提交
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
		usingCursor({
			text: [
				'function baz() {',
				'\tfunction hello() { // something here',
				'\t',
				'',
				'\t}',
				'}',
				''
			],
1371 1372 1373 1374
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
1375 1376
				tabSize: 4,
				trimAutoWhitespace: true
1377
			},
A
Alex Dima 已提交
1378 1379
		}, (model, cursor) => {
			moveTo(cursor, 7, 1, false);
A
Alex Dima 已提交
1380
			assertCursor(cursor, new Selection(7, 1, 7, 1));
A
Alex Dima 已提交
1381

1382
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
1383
			assert.equal(model.getLineContent(7), '\t');
A
Alex Dima 已提交
1384
			assertCursor(cursor, new Selection(7, 2, 7, 2));
A
Alex Dima 已提交
1385
		});
E
Erich Gamma 已提交
1386 1387 1388 1389
	});

	test('bug #16740: [editor] Cut line doesn\'t quite cut the last line', () => {
		// Part 1 => there is text on the last line
A
Alex Dima 已提交
1390
		let text = [
E
Erich Gamma 已提交
1391 1392 1393
			'asdasd',
			'qwerty'
		];
1394
		let model = Model.createFromString(text.join('\n'));
1395
		let cursor = new Cursor(1, new MockConfiguration(null), model, viewModelHelper(model), true);
E
Erich Gamma 已提交
1396 1397

		moveTo(cursor, 2, 1, false);
A
Alex Dima 已提交
1398
		assertCursor(cursor, new Selection(2, 1, 2, 1));
E
Erich Gamma 已提交
1399

1400
		cursorCommand(cursor, H.Cut, null, 'keyboard');
E
Erich Gamma 已提交
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
		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 = [
			'asdasd',
			''
		];
1412
		model = Model.createFromString(text.join('\n'));
1413
		cursor = new Cursor(1, new MockConfiguration(null), model, viewModelHelper(model), true);
E
Erich Gamma 已提交
1414 1415

		moveTo(cursor, 2, 1, false);
A
Alex Dima 已提交
1416
		assertCursor(cursor, new Selection(2, 1, 2, 1));
E
Erich Gamma 已提交
1417

1418
		cursorCommand(cursor, H.Cut, null, 'keyboard');
E
Erich Gamma 已提交
1419 1420 1421
		assert.equal(model.getLineCount(), 1);
		assert.equal(model.getLineContent(1), 'asdasd');

1422
		cursorCommand(cursor, H.Cut, null, 'keyboard');
E
Erich Gamma 已提交
1423 1424 1425 1426 1427 1428 1429
		assert.equal(model.getLineCount(), 1);
		assert.equal(model.getLineContent(1), '');

		cursor.dispose();
		model.dispose();
	});

1430 1431 1432 1433 1434
	test('Bug #11476: Double bracket surrounding + undo is broken', () => {
		usingCursor({
			text: [
				'hello'
			],
1435
			modeId: new SurroundingMode().getId(),
1436
			modelOpts: { tabSize: 4, insertSpaces: true, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
1437 1438 1439
		}, (model, cursor) => {
			moveTo(cursor, 1, 3, false);
			moveTo(cursor, 1, 5, true);
A
Alex Dima 已提交
1440
			assertCursor(cursor, new Selection(1, 3, 1, 5));
1441

1442
			cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard');
A
Alex Dima 已提交
1443
			assertCursor(cursor, new Selection(1, 4, 1, 6));
1444

1445
			cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard');
A
Alex Dima 已提交
1446
			assertCursor(cursor, new Selection(1, 5, 1, 7));
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
		});
	});

	test('issue #1140: Backspace stops prematurely', () => {
		usingCursor({
			text: [
				'function baz() {',
				'  return 1;',
				'};'
			],
1457
			modeId: new SurroundingMode().getId(),
1458
			modelOpts: { tabSize: 4, insertSpaces: true, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
1459 1460 1461
		}, (model, cursor) => {
			moveTo(cursor, 3, 2, false);
			moveTo(cursor, 1, 14, true);
A
Alex Dima 已提交
1462
			assertCursor(cursor, new Selection(3, 2, 1, 14));
1463 1464

			cursorCommand(cursor, H.DeleteLeft);
A
Alex Dima 已提交
1465
			assertCursor(cursor, new Selection(1, 14, 1, 14));
1466 1467 1468 1469
			assert.equal(model.getLineCount(), 1);
			assert.equal(model.getLineContent(1), 'function baz(;');
		});
	});
A
Alex Dima 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480

	test('issue #1336: Insert cursor below on last line adds a cursor to the end of the current line', () => {
		usingCursor({
			text: [
				'abc'
			],
		}, (model, cursor) => {
			cursorCommand(cursor, H.AddCursorDown);
			assert.equal(cursor.getSelections().length, 1);
		});
	});
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497

	test('issue #2205: Multi-cursor pastes in reverse order', () => {
		usingCursor({
			text: [
				'abc',
				'def'
			],
		}, (model, cursor) => {
			moveTo(cursor, 2, 1, false);
			cursorCommand(cursor, H.AddCursorUp);
			assert.equal(cursor.getSelections().length, 2);

			cursorCommand(cursor, H.Paste, { text: '1\n2' });
			assert.equal(model.getLineContent(1), '1abc');
			assert.equal(model.getLineContent(2), '2def');
		});
	});
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515

	test('issue #10212: Pasting entire line does not replace selection', () => {
		usingCursor({
			text: [
				'line1',
				'line2'
			],
		}, (model, cursor) => {
			moveTo(cursor, 2, 1, false);
			moveTo(cursor, 2, 6, true);

			cursorCommand(cursor, H.Paste, { text: 'line1\n', pasteOnNewLine: true });

			assert.equal(model.getLineContent(1), 'line1');
			assert.equal(model.getLineContent(2), 'line1');
			assert.equal(model.getLineContent(3), '');
		});
	});
1516

A
Alex Dima 已提交
1517 1518 1519 1520 1521 1522 1523
	test('issue #3071: Investigate why undo stack gets corrupted', () => {
		usingCursor({
			text: [
				'some lines',
				'and more lines',
				'just some text',
			],
1524
			modeId: null,
1525
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
1526 1527 1528 1529 1530
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);
			moveTo(cursor, 3, 4, true);

			let isFirst = true;
A
Alex Dima 已提交
1531
			model.onDidChangeContent(() => {
A
Alex Dima 已提交
1532 1533
				if (isFirst) {
					isFirst = false;
1534
					cursorCommand(cursor, H.Type, { text: '\t' }, 'keyboard');
A
Alex Dima 已提交
1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
				}
			});

			cursorCommand(cursor, H.Tab);
			assert.equal(model.getValue(), [
				'\t just some text'
			].join('\n'), '001');

			cursorCommand(cursor, H.Undo);
			assert.equal(model.getValue(), [
				'some lines',
				'and more lines',
				'just some text',
			].join('\n'), '002');

			cursorCommand(cursor, H.Undo);
			assert.equal(model.getValue(), [
				'some lines',
				'and more lines',
				'just some text',
			].join('\n'), '003');
		});
	});

A
Alex Dima 已提交
1559 1560 1561 1562 1563 1564 1565 1566 1567
	test('issue #3463: pressing tab adds spaces, but not as many as for a tab', () => {
		usingCursor({
			text: [
				'function a() {',
				'\tvar a = {',
				'\t\tx: 3',
				'\t};',
				'}',
			],
1568
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
1569 1570 1571 1572 1573 1574 1575
		}, (model, cursor) => {
			moveTo(cursor, 3, 2, false);
			cursorCommand(cursor, H.Tab);
			assert.equal(model.getLineContent(3), '\t    \tx: 3');
		});
	});

1576 1577 1578
	test('issue #4312: trying to type a tab character over a sequence of spaces results in unexpected behaviour', () => {
		usingCursor({
			text: [
1579
				'var foo = 123;       // this is a comment',
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
				'var bar = 4;       // another comment'
			],
			modelOpts: { insertSpaces: false, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
		}, (model, cursor) => {
			moveTo(cursor, 1, 15, false);
			moveTo(cursor, 1, 22, true);
			cursorCommand(cursor, H.Tab);
			assert.equal(model.getLineContent(1), 'var foo = 123;\t// this is a comment');
		});
	});

1591 1592 1593 1594 1595 1596 1597
	test('issue #832: deleteWordLeft', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 37, false);
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +5 */', '001');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +5 ', '002');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +', '003');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 ', '004');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= ', '005');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a', '006');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text ', '007');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some ', '008');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just ', '009');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   /* ', '010');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '   ', '011');
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), '', '012');
1610 1611 1612
		});
	});

1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
	test('deleteWordStartLeft', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 37, false);

			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +5 ', '001');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +', '002');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 ', '003');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= ', '004');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a', '005');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text ', '006');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some ', '007');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just ', '008');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   /* ', '009');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '   ', '010');
			deleteWordStartLeft(cursor); assert.equal(model.getLineContent(1), '', '011');
		});
	});

	test('deleteWordEndLeft', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 37, false);
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +5 */', '001');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +5', '002');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3 +', '003');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+= 3', '004');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a+=', '005');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text a', '006');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some text', '007');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just some', '008');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /* Just', '009');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '   /*', '010');
			deleteWordEndLeft(cursor); assert.equal(model.getLineContent(1), '', '011');
		});
	});

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
	test('issue #832: deleteWordRight', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5-3 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '/* Just some text a+= 3 +5-3 */  ', '001');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' Just some text a+= 3 +5-3 */  ', '002');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' some text a+= 3 +5-3 */  ', '003');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' text a+= 3 +5-3 */  ', '004');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' a+= 3 +5-3 */  ', '005');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '+= 3 +5-3 */  ', '006');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' 3 +5-3 */  ', '007');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' +5-3 */  ', '008');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '5-3 */  ', '009');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '-3 */  ', '010');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '3 */  ', '011');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), ' */  ', '012');
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), '  ', '013');
		});
	});
1678

1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
	test('issue #3882: deleteWordRight', () => {
		usingCursor({
			text: [
				'public void Add( int x,',
				'                 int y )'
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 24, false);
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), 'public void Add( int x,int y )', '001');
		});
	});

	test('issue #3882: deleteWordStartRight', () => {
		usingCursor({
			text: [
				'public void Add( int x,',
				'                 int y )'
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 24, false);
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), 'public void Add( int x,int y )', '001');
		});
	});

	test('issue #3882: deleteWordEndRight', () => {
		usingCursor({
			text: [
				'public void Add( int x,',
				'                 int y )'
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 24, false);
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), 'public void Add( int x,int y )', '001');
		});
	});

1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
	test('deleteWordStartRight', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5-3 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);

			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '/* Just some text a+= 3 +5-3 */  ', '001');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), 'Just some text a+= 3 +5-3 */  ', '002');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), 'some text a+= 3 +5-3 */  ', '003');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), 'text a+= 3 +5-3 */  ', '004');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), 'a+= 3 +5-3 */  ', '005');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '+= 3 +5-3 */  ', '006');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '3 +5-3 */  ', '007');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '+5-3 */  ', '008');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '5-3 */  ', '009');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '-3 */  ', '010');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '3 */  ', '011');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '*/  ', '012');
			deleteWordStartRight(cursor); assert.equal(model.getLineContent(1), '', '013');
		});
	});

	test('deleteWordEndRight', () => {
		usingCursor({
			text: [
				'   /* Just some text a+= 3 +5-3 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' Just some text a+= 3 +5-3 */  ', '001');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' some text a+= 3 +5-3 */  ', '002');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' text a+= 3 +5-3 */  ', '003');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' a+= 3 +5-3 */  ', '004');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), '+= 3 +5-3 */  ', '005');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' 3 +5-3 */  ', '006');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' +5-3 */  ', '007');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), '5-3 */  ', '008');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), '-3 */  ', '009');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), '3 */  ', '010');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), ' */  ', '011');
			deleteWordEndRight(cursor); assert.equal(model.getLineContent(1), '  ', '012');
		});
	});

1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
	test('issue #832: moveWordLeft', () => {
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 50, false);

			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 '.length + 1, '001');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + '.length + 1, '002');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 '.length + 1, '003');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '004');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '005');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '006');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 '.length + 1, '007');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= '.length + 1, '008');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '009');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text '.length + 1, '010');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   '.length + 1, '011');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   '.length + 1, '012');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just '.length + 1, '013');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   /* '.length + 1, '014');
			moveWordLeft(cursor); assert.equal(cursor.getPosition().column, '   '.length + 1, '015');
		});
	});
1786

1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
	test('moveWordStartLeft', () => {
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 50, false);

			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 '.length + 1, '001');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + '.length + 1, '002');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 '.length + 1, '003');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '004');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '005');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '006');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 '.length + 1, '007');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= '.length + 1, '008');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '009');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text '.length + 1, '010');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   '.length + 1, '011');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   '.length + 1, '012');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just '.length + 1, '013');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   /* '.length + 1, '014');
			moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, '   '.length + 1, '015');
		});
	});

	test('moveWordEndLeft', () => {
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 50, false);

			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */'.length + 1, '001');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7'.length + 1, '002');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 +'.length + 1, '003');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3'.length + 1, '004');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '005');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '006');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '007');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3'.length + 1, '008');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+='.length + 1, '009');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '010');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text'.length + 1, '011');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more'.length + 1, '012');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just some'.length + 1, '013');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /* Just'.length + 1, '014');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, '   /*'.length + 1, '015');
			moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ''.length + 1, '016');
		});
	});

	test('issue #832: moveWordRight', () => {
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);

			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /*'.length + 1, '001');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just'.length + 1, '003');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some'.length + 1, '004');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more'.length + 1, '005');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text'.length + 1, '006');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '007');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+='.length + 1, '008');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3'.length + 1, '009');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '010');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '011');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '012');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3'.length + 1, '013');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 +'.length + 1, '014');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7'.length + 1, '015');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */'.length + 1, '016');
			moveWordRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */  '.length + 1, '016');

		});
	});
1867

1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922
	test('moveWordEndRight', () => {
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);

			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /*'.length + 1, '001');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just'.length + 1, '003');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some'.length + 1, '004');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more'.length + 1, '005');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text'.length + 1, '006');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '007');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+='.length + 1, '008');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3'.length + 1, '009');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '010');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '011');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '012');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3'.length + 1, '013');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 +'.length + 1, '014');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7'.length + 1, '015');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */'.length + 1, '016');
			moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */  '.length + 1, '016');

		});
	});

	test('moveWordStartRight', () => {
		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);

			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   '.length + 1, '001');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* '.length + 1, '002');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just '.length + 1, '003');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   '.length + 1, '004');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   '.length + 1, '005');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text '.length + 1, '006');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a'.length + 1, '007');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= '.length + 1, '008');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 '.length + 1, '009');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +'.length + 1, '010');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5'.length + 1, '011');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-'.length + 1, '012');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 '.length + 1, '013');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + '.length + 1, '014');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 '.length + 1, '015');
			moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, '   /* Just some   more   text a+= 3 +5-3 + 7 */  '.length + 1, '016');
		});
	});

1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
	test('issue #832: word right', () => {

		usingCursor({
			text: [
				'   /* Just some   more   text a+= 3 +5-3 + 7 */  '
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 1, false);

			function assertWordRight(col, expectedCol) {
				cursorCommand(cursor, col === 1 ? H.WordSelect : H.WordSelectDrag, {
					position: {
						lineNumber: 1,
						column: col
					},
					preference: 'right'
				});

				assert.equal(cursor.getSelection().startColumn, 1, 'TEST FOR ' + col);
				assert.equal(cursor.getSelection().endColumn, expectedCol, 'TEST FOR ' + col);
			}

J
Johannes Rieken 已提交
1945 1946 1947 1948 1949 1950 1951 1952 1953
			assertWordRight(1, '   '.length + 1);
			assertWordRight(2, '   '.length + 1);
			assertWordRight(3, '   '.length + 1);
			assertWordRight(4, '   '.length + 1);
			assertWordRight(5, '   /'.length + 1);
			assertWordRight(6, '   /*'.length + 1);
			assertWordRight(7, '   /* '.length + 1);
			assertWordRight(8, '   /* Just'.length + 1);
			assertWordRight(9, '   /* Just'.length + 1);
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
			assertWordRight(10, '   /* Just'.length + 1);
			assertWordRight(11, '   /* Just'.length + 1);
			assertWordRight(12, '   /* Just '.length + 1);
			assertWordRight(13, '   /* Just some'.length + 1);
			assertWordRight(14, '   /* Just some'.length + 1);
			assertWordRight(15, '   /* Just some'.length + 1);
			assertWordRight(16, '   /* Just some'.length + 1);
			assertWordRight(17, '   /* Just some '.length + 1);
			assertWordRight(18, '   /* Just some  '.length + 1);
			assertWordRight(19, '   /* Just some   '.length + 1);
			assertWordRight(20, '   /* Just some   more'.length + 1);
			assertWordRight(21, '   /* Just some   more'.length + 1);
			assertWordRight(22, '   /* Just some   more'.length + 1);
			assertWordRight(23, '   /* Just some   more'.length + 1);
			assertWordRight(24, '   /* Just some   more '.length + 1);
			assertWordRight(25, '   /* Just some   more  '.length + 1);
			assertWordRight(26, '   /* Just some   more   '.length + 1);
			assertWordRight(27, '   /* Just some   more   text'.length + 1);
			assertWordRight(28, '   /* Just some   more   text'.length + 1);
			assertWordRight(29, '   /* Just some   more   text'.length + 1);
			assertWordRight(30, '   /* Just some   more   text'.length + 1);
			assertWordRight(31, '   /* Just some   more   text '.length + 1);
			assertWordRight(32, '   /* Just some   more   text a'.length + 1);
			assertWordRight(33, '   /* Just some   more   text a+'.length + 1);
			assertWordRight(34, '   /* Just some   more   text a+='.length + 1);
			assertWordRight(35, '   /* Just some   more   text a+= '.length + 1);
			assertWordRight(36, '   /* Just some   more   text a+= 3'.length + 1);
			assertWordRight(37, '   /* Just some   more   text a+= 3 '.length + 1);
			assertWordRight(38, '   /* Just some   more   text a+= 3 +'.length + 1);
			assertWordRight(39, '   /* Just some   more   text a+= 3 +5'.length + 1);
			assertWordRight(40, '   /* Just some   more   text a+= 3 +5-'.length + 1);
			assertWordRight(41, '   /* Just some   more   text a+= 3 +5-3'.length + 1);
			assertWordRight(42, '   /* Just some   more   text a+= 3 +5-3 '.length + 1);
			assertWordRight(43, '   /* Just some   more   text a+= 3 +5-3 +'.length + 1);
			assertWordRight(44, '   /* Just some   more   text a+= 3 +5-3 + '.length + 1);
			assertWordRight(45, '   /* Just some   more   text a+= 3 +5-3 + 7'.length + 1);
			assertWordRight(46, '   /* Just some   more   text a+= 3 +5-3 + 7 '.length + 1);
			assertWordRight(47, '   /* Just some   more   text a+= 3 +5-3 + 7 *'.length + 1);
			assertWordRight(48, '   /* Just some   more   text a+= 3 +5-3 + 7 */'.length + 1);
			assertWordRight(49, '   /* Just some   more   text a+= 3 +5-3 + 7 */ '.length + 1);
			assertWordRight(50, '   /* Just some   more   text a+= 3 +5-3 + 7 */  '.length + 1);
		});
	});
1997 1998 1999 2000 2001 2002 2003 2004 2005

	test('issue #3882 (1): Ctrl+Delete removing entire line when used at the end of line', () => {
		usingCursor({
			text: [
				'A line with text.',
				'   And another one'
			],
		}, (model, cursor) => {
			moveTo(cursor, 1, 18, false);
2006
			deleteWordRight(cursor); assert.equal(model.getLineContent(1), 'A line with text.And another one', '001');
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
		});
	});

	test('issue #3882 (2): Ctrl+Delete removing entire line when used at the end of line', () => {
		usingCursor({
			text: [
				'A line with text.',
				'   And another one'
			],
		}, (model, cursor) => {
			moveTo(cursor, 2, 1, false);
			deleteWordLeft(cursor); assert.equal(model.getLineContent(1), 'A line with text.   And another one', '001');
		});
	});
A
Alex Dima 已提交
2021

2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
	test('issue Microsoft/monaco-editor#108 part 1/2: Auto indentation on Enter with selection is half broken', () => {
		usingCursor({
			text: [
				'function baz() {',
				'\tvar x = 1;',
				'\t\t\t\t\t\t\treturn x;',
				'}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
2037
			modeId: new OnEnterMode(IndentAction.None).getId(),
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063
		}, (model, cursor) => {
			moveTo(cursor, 3, 8, false);
			moveTo(cursor, 2, 12, true);
			assertCursor(cursor, new Selection(3, 8, 2, 12));

			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
			assert.equal(model.getLineContent(3), '\treturn x;');
			assertCursor(cursor, new Position(3, 2));
		});
	});

	test('issue Microsoft/monaco-editor#108 part 2/2: Auto indentation on Enter with selection is half broken', () => {
		usingCursor({
			text: [
				'function baz() {',
				'\tvar x = 1;',
				'\t\t\t\t\t\t\treturn x;',
				'}'
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			},
2064
			modeId: new OnEnterMode(IndentAction.None).getId(),
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
		}, (model, cursor) => {
			moveTo(cursor, 2, 12, false);
			moveTo(cursor, 3, 8, true);
			assertCursor(cursor, new Selection(2, 12, 3, 8));

			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
			assert.equal(model.getLineContent(3), '\treturn x;');
			assertCursor(cursor, new Position(3, 2));
		});
	});
2075 2076 2077 2078 2079 2080 2081 2082 2083

	test('issue #9675: Undo/Redo adds a stop in between CHN Characters', () => {
		usingCursor({
			text: [
			]
		}, (model, cursor) => {
			assertCursor(cursor, new Position(1, 1));

			// Typing sennsei in Japanese - Hiragana
J
Johannes Rieken 已提交
2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
			cursorCommand(cursor, H.Type, { text: '' }, 'keyboard');
			cursorCommand(cursor, H.ReplacePreviousChar, { text: '', replaceCharCnt: 1 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せn', replaceCharCnt: 1 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せん', replaceCharCnt: 2 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんs', replaceCharCnt: 2 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせ', replaceCharCnt: 3 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせ', replaceCharCnt: 3 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせい', replaceCharCnt: 3 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせい', replaceCharCnt: 4 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせい', replaceCharCnt: 4 });
			cursorCommand(cursor, H.ReplacePreviousChar, { text: 'せんせい', replaceCharCnt: 4 });
2095 2096 2097 2098 2099 2100 2101 2102 2103

			assert.equal(model.getLineContent(1), 'せんせい');
			assertCursor(cursor, new Position(1, 5));

			cursorCommand(cursor, H.Undo);
			assert.equal(model.getLineContent(1), '');
			assertCursor(cursor, new Position(1, 1));
		});
	});
2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
});

suite('Editor Controller - Cursor Configuration', () => {

	test('Cursor honors insertSpaces configuration on new line', () => {
		usingCursor({
			text: [
				'    \tMy First Line\t ',
				'\tMy Second Line',
				'    Third Line',
				'',
				'1'
			],
2117
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
2118
		}, (model, cursor) => {
2119 2120
			cursorCommand(cursor, H.MoveTo, { position: new Position(1, 21) }, 'keyboard');
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2121 2122 2123 2124 2125
			assert.equal(model.getLineContent(1), '    \tMy First Line\t ');
			assert.equal(model.getLineContent(2), '        ');
		});
	});

E
Erich Gamma 已提交
2126
	test('Cursor honors insertSpaces configuration on tab', () => {
A
Alex Dima 已提交
2127 2128 2129 2130 2131 2132 2133 2134
		usingCursor({
			text: [
				'    \tMy First Line\t ',
				'My Second Line123',
				'    Third Line',
				'',
				'1'
			],
2135
			modelOpts: { insertSpaces: true, tabSize: 13, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
2136 2137
		}, (model, cursor) => {
			// Tab on column 1
2138 2139
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 1) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2140
			assert.equal(model.getLineContent(2), '             My Second Line123');
2141
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2142 2143 2144

			// Tab on column 2
			assert.equal(model.getLineContent(2), 'My Second Line123');
2145 2146
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 2) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2147
			assert.equal(model.getLineContent(2), 'M            y Second Line123');
2148
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2149 2150 2151

			// Tab on column 3
			assert.equal(model.getLineContent(2), 'My Second Line123');
2152 2153
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 3) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2154
			assert.equal(model.getLineContent(2), 'My            Second Line123');
2155
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2156 2157 2158

			// Tab on column 4
			assert.equal(model.getLineContent(2), 'My Second Line123');
2159 2160
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 4) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2161
			assert.equal(model.getLineContent(2), 'My           Second Line123');
2162
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2163 2164 2165

			// Tab on column 5
			assert.equal(model.getLineContent(2), 'My Second Line123');
2166 2167
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 5) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2168
			assert.equal(model.getLineContent(2), 'My S         econd Line123');
2169
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2170 2171 2172

			// Tab on column 5
			assert.equal(model.getLineContent(2), 'My Second Line123');
2173 2174
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 5) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2175
			assert.equal(model.getLineContent(2), 'My S         econd Line123');
2176
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2177 2178 2179

			// Tab on column 13
			assert.equal(model.getLineContent(2), 'My Second Line123');
2180 2181
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 13) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2182
			assert.equal(model.getLineContent(2), 'My Second Li ne123');
2183
			cursorCommand(cursor, H.Undo, null, 'keyboard');
A
Alex Dima 已提交
2184 2185 2186

			// Tab on column 14
			assert.equal(model.getLineContent(2), 'My Second Line123');
2187 2188
			cursorCommand(cursor, H.MoveTo, { position: new Position(2, 14) }, 'keyboard');
			cursorCommand(cursor, H.Tab, null, 'keyboard');
A
Alex Dima 已提交
2189 2190
			assert.equal(model.getLineContent(2), 'My Second Lin             e123');
		});
E
Erich Gamma 已提交
2191 2192 2193
	});

	test('Enter auto-indents with insertSpaces setting 1', () => {
A
Alex Dima 已提交
2194 2195 2196 2197
		usingCursor({
			text: [
				'\thello'
			],
2198
			modeId: new OnEnterMode(IndentAction.Indent).getId(),
2199
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
2200 2201
		}, (model, cursor) => {
			moveTo(cursor, 1, 7, false);
A
Alex Dima 已提交
2202
			assertCursor(cursor, new Selection(1, 7, 1, 7));
A
Alex Dima 已提交
2203

2204
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
A
Alex Dima 已提交
2205 2206
			assert.equal(model.getValue(EndOfLinePreference.CRLF), '\thello\r\n        ');
		});
E
Erich Gamma 已提交
2207 2208 2209
	});

	test('Enter auto-indents with insertSpaces setting 2', () => {
A
Alex Dima 已提交
2210 2211 2212 2213
		usingCursor({
			text: [
				'\thello'
			],
2214
			modeId: new OnEnterMode(IndentAction.None).getId(),
2215
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
2216 2217
		}, (model, cursor) => {
			moveTo(cursor, 1, 7, false);
A
Alex Dima 已提交
2218
			assertCursor(cursor, new Selection(1, 7, 1, 7));
A
Alex Dima 已提交
2219

2220
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
A
Alex Dima 已提交
2221 2222
			assert.equal(model.getValue(EndOfLinePreference.CRLF), '\thello\r\n    ');
		});
E
Erich Gamma 已提交
2223 2224 2225
	});

	test('Enter auto-indents with insertSpaces setting 3', () => {
A
Alex Dima 已提交
2226 2227 2228 2229
		usingCursor({
			text: [
				'\thell()'
			],
2230
			modeId: new OnEnterMode(IndentAction.IndentOutdent).getId(),
2231
			modelOpts: { insertSpaces: true, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
A
Alex Dima 已提交
2232 2233
		}, (model, cursor) => {
			moveTo(cursor, 1, 7, false);
A
Alex Dima 已提交
2234
			assertCursor(cursor, new Selection(1, 7, 1, 7));
A
Alex Dima 已提交
2235

2236
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
A
Alex Dima 已提交
2237 2238
			assert.equal(model.getValue(EndOfLinePreference.CRLF), '\thell(\r\n        \r\n    )');
		});
E
Erich Gamma 已提交
2239 2240 2241
	});

	test('Insert line before', () => {
J
Johannes Rieken 已提交
2242
		let testInsertLineBefore = (lineNumber: number, column: number, callback: (model: Model, cursor: Cursor) => void) => {
A
Alex Dima 已提交
2243 2244 2245 2246 2247 2248 2249
			usingCursor({
				text: [
					'First line',
					'Second line',
					'Third line'
				],
			}, (model, cursor) => {
E
Erich Gamma 已提交
2250
				moveTo(cursor, lineNumber, column, false);
A
Alex Dima 已提交
2251
				assertCursor(cursor, new Position(lineNumber, column));
E
Erich Gamma 已提交
2252

2253
				cursorCommand(cursor, H.LineInsertBefore, null, 'keyboard');
E
Erich Gamma 已提交
2254 2255 2256 2257 2258
				callback(model, cursor);
			});
		};

		testInsertLineBefore(1, 3, (model, cursor) => {
A
Alex Dima 已提交
2259
			assertCursor(cursor, new Selection(1, 1, 1, 1));
E
Erich Gamma 已提交
2260 2261 2262 2263 2264 2265 2266
			assert.equal(model.getLineContent(1), '');
			assert.equal(model.getLineContent(2), 'First line');
			assert.equal(model.getLineContent(3), 'Second line');
			assert.equal(model.getLineContent(4), 'Third line');
		});

		testInsertLineBefore(2, 3, (model, cursor) => {
A
Alex Dima 已提交
2267
			assertCursor(cursor, new Selection(2, 1, 2, 1));
E
Erich Gamma 已提交
2268 2269 2270 2271 2272 2273 2274
			assert.equal(model.getLineContent(1), 'First line');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), 'Second line');
			assert.equal(model.getLineContent(4), 'Third line');
		});

		testInsertLineBefore(3, 3, (model, cursor) => {
A
Alex Dima 已提交
2275
			assertCursor(cursor, new Selection(3, 1, 3, 1));
E
Erich Gamma 已提交
2276 2277 2278 2279 2280 2281 2282 2283
			assert.equal(model.getLineContent(1), 'First line');
			assert.equal(model.getLineContent(2), 'Second line');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), 'Third line');
		});
	});

	test('Insert line after', () => {
J
Johannes Rieken 已提交
2284
		let testInsertLineAfter = (lineNumber: number, column: number, callback: (model: Model, cursor: Cursor) => void) => {
A
Alex Dima 已提交
2285 2286 2287 2288 2289 2290 2291
			usingCursor({
				text: [
					'First line',
					'Second line',
					'Third line'
				],
			}, (model, cursor) => {
E
Erich Gamma 已提交
2292
				moveTo(cursor, lineNumber, column, false);
A
Alex Dima 已提交
2293
				assertCursor(cursor, new Position(lineNumber, column));
E
Erich Gamma 已提交
2294

2295
				cursorCommand(cursor, H.LineInsertAfter, null, 'keyboard');
E
Erich Gamma 已提交
2296 2297 2298 2299 2300
				callback(model, cursor);
			});
		};

		testInsertLineAfter(1, 3, (model, cursor) => {
A
Alex Dima 已提交
2301
			assertCursor(cursor, new Selection(2, 1, 2, 1));
E
Erich Gamma 已提交
2302 2303 2304 2305 2306 2307 2308
			assert.equal(model.getLineContent(1), 'First line');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), 'Second line');
			assert.equal(model.getLineContent(4), 'Third line');
		});

		testInsertLineAfter(2, 3, (model, cursor) => {
A
Alex Dima 已提交
2309
			assertCursor(cursor, new Selection(3, 1, 3, 1));
E
Erich Gamma 已提交
2310 2311 2312 2313 2314 2315 2316
			assert.equal(model.getLineContent(1), 'First line');
			assert.equal(model.getLineContent(2), 'Second line');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), 'Third line');
		});

		testInsertLineAfter(3, 3, (model, cursor) => {
A
Alex Dima 已提交
2317
			assertCursor(cursor, new Selection(4, 1, 4, 1));
E
Erich Gamma 已提交
2318 2319 2320 2321 2322 2323
			assert.equal(model.getLineContent(1), 'First line');
			assert.equal(model.getLineContent(2), 'Second line');
			assert.equal(model.getLineContent(3), 'Third line');
			assert.equal(model.getLineContent(4), '');
		});
	});
2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340

	test('removeAutoWhitespace off', () => {
		usingCursor({
			text: [
				'    some  line abc  '
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: false
			}
		}, (model, cursor) => {

			// Move cursor to the end, verify that we do not trim whitespaces if line has values
			moveTo(cursor, 1, model.getLineContent(1).length + 1);
2341
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2342 2343 2344 2345
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '    ');

			// Try to enter again, we should trimmed previous line
2346
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '    ');
			assert.equal(model.getLineContent(3), '    ');
		});
	});

	test('removeAutoWhitespace on: removes only whitespace the cursor added 1', () => {
		usingCursor({
			text: [
				'    '
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
			}
		}, (model, cursor) => {
			moveTo(cursor, 1, model.getLineContent(1).length + 1);
2367
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2368 2369 2370
			assert.equal(model.getLineContent(1), '    ');
			assert.equal(model.getLineContent(2), '    ');

2371
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2372 2373 2374 2375 2376 2377
			assert.equal(model.getLineContent(1), '    ');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), '    ');
		});
	});

2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389
	test('issue #6862: Editor removes auto inserted indentation when formatting on type', () => {
		usingCursor({
			text: [
				'function foo (params: string) {}'
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
			},
2390
			modeId: new OnEnterMode(IndentAction.IndentOutdent).getId(),
2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
		}, (model, cursor) => {

			moveTo(cursor, 1, 32);
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
			assert.equal(model.getLineContent(1), 'function foo (params: string) {');
			assert.equal(model.getLineContent(2), '    ');
			assert.equal(model.getLineContent(3), '}');

			class TestCommand implements ICommand {

				private _selectionId: string = null;

				public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
					builder.addEditOperation(new Range(1, 13, 1, 14), '');
					this._selectionId = builder.trackSelection(cursor.getSelection());
				}

				public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
					return helper.getTrackedSelection(this._selectionId);
				}

			}

			cursor.trigger('autoFormat', Handler.ExecuteCommand, new TestCommand());
			assert.equal(model.getLineContent(1), 'function foo(params: string) {');
			assert.equal(model.getLineContent(2), '    ');
			assert.equal(model.getLineContent(3), '}');
		});
	});

2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
	test('removeAutoWhitespace on: removes only whitespace the cursor added 2', () => {
		usingCursor({
			text: [
				'    if (a) {',
				'        ',
				'',
				'',
				'    }'
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
			}
		}, (model, cursor) => {

			moveTo(cursor, 3, 1);
2440
			cursorCommand(cursor, H.Tab, null, 'keyboard');
2441 2442 2443 2444 2445 2446 2447
			assert.equal(model.getLineContent(1), '    if (a) {');
			assert.equal(model.getLineContent(2), '        ');
			assert.equal(model.getLineContent(3), '    ');
			assert.equal(model.getLineContent(4), '');
			assert.equal(model.getLineContent(5), '    }');

			moveTo(cursor, 4, 1);
2448
			cursorCommand(cursor, H.Tab, null, 'keyboard');
2449 2450 2451 2452 2453 2454 2455
			assert.equal(model.getLineContent(1), '    if (a) {');
			assert.equal(model.getLineContent(2), '        ');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), '    ');
			assert.equal(model.getLineContent(5), '    }');

			moveTo(cursor, 5, model.getLineMaxColumn(5));
2456
			cursorCommand(cursor, H.Type, { text: 'something' }, 'keyboard');
2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480
			assert.equal(model.getLineContent(1), '    if (a) {');
			assert.equal(model.getLineContent(2), '        ');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), '');
			assert.equal(model.getLineContent(5), '    }something');
		});
	});

	test('removeAutoWhitespace on: test 1', () => {
		usingCursor({
			text: [
				'    some  line abc  '
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
			}
		}, (model, cursor) => {

			// Move cursor to the end, verify that we do not trim whitespaces if line has values
			moveTo(cursor, 1, model.getLineContent(1).length + 1);
2481
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2482 2483 2484 2485
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '    ');

			// Try to enter again, we should trimmed previous line
2486
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2487 2488 2489 2490 2491
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), '    ');

			// More whitespaces
2492
			cursorCommand(cursor, H.Tab, null, 'keyboard');
2493 2494 2495 2496 2497
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), '        ');

			// Enter and verify that trimmed again
2498
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2499 2500 2501 2502 2503 2504 2505
			assert.equal(model.getLineContent(1), '    some  line abc  ');
			assert.equal(model.getLineContent(2), '');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), '        ');

			// Trimmed if we will keep only text
			moveTo(cursor, 1, 5);
2506
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2507 2508 2509 2510 2511 2512 2513 2514 2515
			assert.equal(model.getLineContent(1), '    ');
			assert.equal(model.getLineContent(2), '    some  line abc  ');
			assert.equal(model.getLineContent(3), '');
			assert.equal(model.getLineContent(4), '');
			assert.equal(model.getLineContent(5), '');

			// Trimmed if we will keep only text by selection
			moveTo(cursor, 2, 5);
			moveTo(cursor, 3, 1, true);
2516
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2517 2518
			assert.equal(model.getLineContent(1), '    ');
			assert.equal(model.getLineContent(2), '    ');
2519
			assert.equal(model.getLineContent(3), '    ');
2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
			assert.equal(model.getLineContent(4), '');
			assert.equal(model.getLineContent(5), '');
		});
	});

	test('UseTabStops is off', () => {
		usingCursor({
			text: [
				'    x',
				'        a    ',
				'    '
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
2538 2539 2540
			},
			editorOpts: {
				useTabStops: false
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562
			}
		}, (model, cursor) => {
			// DeleteLeft removes just one whitespace
			moveTo(cursor, 2, 9);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(2), '       a    ');
		});
	});

	test('Backspace removes whitespaces with tab size', () => {
		usingCursor({
			text: [
				' \t \t     x',
				'        a    ',
				'    '
			],
			modelOpts: {
				insertSpaces: true,
				tabSize: 4,
				detectIndentation: false,
				defaultEOL: DefaultEndOfLine.LF,
				trimAutoWhitespace: true
2563 2564 2565
			},
			editorOpts: {
				useTabStops: true
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634
			}
		}, (model, cursor) => {
			// DeleteLeft does not remove tab size, because some text exists before
			moveTo(cursor, 2, model.getLineContent(2).length + 1);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(2), '        a   ');

			// DeleteLeft removes tab size = 4
			moveTo(cursor, 2, 9);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(2), '    a   ');

			// DeleteLeft removes tab size = 4
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(2), 'a   ');

			// Undo DeleteLeft - get us back to original indentation
			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getLineContent(2), '        a   ');

			// Nothing is broken when cursor is in (1,1)
			moveTo(cursor, 1, 1);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(1), ' \t \t     x');

			// DeleteLeft stops at tab stops even in mixed whitespace case
			moveTo(cursor, 1, 10);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(1), ' \t \t    x');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(1), ' \t \tx');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(1), ' \tx');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(1), 'x');

			// DeleteLeft on last line
			moveTo(cursor, 3, model.getLineContent(3).length + 1);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(3), '');

			// DeleteLeft with removing new line symbol
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), 'x\n        a   ');

			// In case of selection DeleteLeft only deletes selected text
			moveTo(cursor, 2, 3);
			moveTo(cursor, 2, 4, true);
			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getLineContent(2), '       a   ');
		});
	});

	test('PR #5423: Auto indent + undo + redo is funky', () => {
		usingCursor({
			text: [
				''
			],
			modelOpts: {
				defaultEOL: DefaultEndOfLine.LF,
				detectIndentation: false,
				insertSpaces: false,
				tabSize: 4,
				trimAutoWhitespace: true
			}
		}, (model, cursor) => {
2635
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2636 2637 2638 2639 2640
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n', 'assert1');

			cursorCommand(cursor, H.Tab, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\t', 'assert2');

J
Johannes Rieken 已提交
2641
			cursorCommand(cursor, H.Type, { text: 'y' }, 'keyboard');
2642 2643
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty', 'assert2');

J
Johannes Rieken 已提交
2644
			cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\n\t', 'assert3');

			cursorCommand(cursor, H.Type, { text: 'x' });
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\n\tx', 'assert4');

			cursorCommand(cursor, H.CursorLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\n\tx', 'assert5');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\nx', 'assert6');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\tyx', 'assert7');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\tx', 'assert8');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert9');

			cursorCommand(cursor, H.DeleteLeft, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), 'x', 'assert10');

			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert11');

			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\nx', 'assert12');

			cursorCommand(cursor, H.Undo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\n\tx', 'assert13');

			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\n\ty\nx', 'assert14');

			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), '\nx', 'assert15');

			cursorCommand(cursor, H.Redo, {});
			assert.equal(model.getValue(EndOfLinePreference.LF), 'x', 'assert16');
		});
	});
E
Erich Gamma 已提交
2687 2688 2689
});

interface ICursorOpts {
A
Alex Dima 已提交
2690
	text: string[];
2691
	modeId?: string;
2692
	modelOpts?: ITextModelCreationOptions;
2693
	editorOpts?: IEditorOptions;
E
Erich Gamma 已提交
2694 2695
}

J
Johannes Rieken 已提交
2696
function usingCursor(opts: ICursorOpts, callback: (model: Model, cursor: Cursor) => void): void {
2697
	let model = Model.createFromString(opts.text.join('\n'), opts.modelOpts, opts.modeId);
2698
	let config = new MockConfiguration(opts.editorOpts);
2699
	let cursor = new Cursor(1, config, model, viewModelHelper(model), false);
E
Erich Gamma 已提交
2700 2701 2702 2703 2704 2705

	callback(model, cursor);

	cursor.dispose();
	config.dispose();
	model.dispose();
2706
}