Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/browser/commands/shiftCommand.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
9
import { ShiftCommand } from '../../../common/commands/shiftCommand.js';
10
import { EditorAutoIndentStrategy } from '../../../common/config/editorOptions.js';
11
import { ISingleEditOperation } from '../../../common/core/editOperation.js';
12
import { Range } from '../../../common/core/range.js';
13
import { Selection } from '../../../common/core/selection.js';
14
import { ILanguageService } from '../../../common/languages/language.js';
15
import { ILanguageConfigurationService } from '../../../common/languages/languageConfigurationRegistry.js';
16
import { getEditOperation, testCommand } from '../testCommand.js';
17
import { javascriptOnEnterRules } from '../../common/modes/supports/onEnterRules.js';
18
import { TestLanguageConfigurationService } from '../../common/modes/testLanguageConfigurationService.js';
19
import { withEditorModel } from '../../common/testTextModel.js';
20
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
21
22
/**
23
* Create single edit operation
24
*/
25
function createSingleEditOp(text: string, positionLineNumber: number, positionColumn: number, selectionLineNumber: number = positionLineNumber, selectionColumn: number = positionColumn): ISingleEditOperation {
26
return {
27
range: new Range(selectionLineNumber, selectionColumn, positionLineNumber, positionColumn),
28
text: text,
29
forceMoveMarkers: false
30
};
31
}
32
33
class DocBlockCommentMode extends Disposable {
34
35
public static languageId = 'commentMode';
36
public readonly languageId = DocBlockCommentMode.languageId;
37
38
constructor(
39
@ILanguageService languageService: ILanguageService,
40
@ILanguageConfigurationService languageConfigurationService: ILanguageConfigurationService
41
) {
42
super();
43
this._register(languageService.registerLanguage({ id: this.languageId }));
44
this._register(languageConfigurationService.register(this.languageId, {
45
brackets: [
46
['(', ')'],
47
['{', '}'],
48
['[', ']']
49
],
50
51
onEnterRules: javascriptOnEnterRules
52
}));
53
}
54
}
55
56
function testShiftCommand(lines: string[], languageId: string | null, useTabStops: boolean, selection: Selection, expectedLines: string[], expectedSelection: Selection, prepare?: (accessor: ServicesAccessor, disposables: DisposableStore) => void): void {
57
testCommand(lines, languageId, selection, (accessor, sel) => new ShiftCommand(sel, {
58
isUnshift: false,
59
tabSize: 4,
60
indentSize: 4,
61
insertSpaces: false,
62
useTabStops: useTabStops,
63
autoIndent: EditorAutoIndentStrategy.Full,
64
}, accessor.get(ILanguageConfigurationService)), expectedLines, expectedSelection, undefined, prepare);
65
}
66
67
function testUnshiftCommand(lines: string[], languageId: string | null, useTabStops: boolean, selection: Selection, expectedLines: string[], expectedSelection: Selection, prepare?: (accessor: ServicesAccessor, disposables: DisposableStore) => void): void {
68
testCommand(lines, languageId, selection, (accessor, sel) => new ShiftCommand(sel, {
69
isUnshift: true,
70
tabSize: 4,
71
indentSize: 4,
72
insertSpaces: false,
73
useTabStops: useTabStops,
74
autoIndent: EditorAutoIndentStrategy.Full,
75
}, accessor.get(ILanguageConfigurationService)), expectedLines, expectedSelection, undefined, prepare);
76
}
77
78
function prepareDocBlockCommentLanguage(accessor: ServicesAccessor, disposables: DisposableStore) {
79
const languageConfigurationService = accessor.get(ILanguageConfigurationService);
80
const languageService = accessor.get(ILanguageService);
81
disposables.add(new DocBlockCommentMode(languageService, languageConfigurationService));
82
}
83
84
suite('Editor Commands - ShiftCommand', () => {
85
86
ensureNoDisposablesAreLeakedInTestSuite();
87
88
// --------- shift
89
90
test('Bug 9503: Shifting without any selection', () => {
91
testShiftCommand(
92
[
93
'My First Line',
94
'\t\tMy Second Line',
95
' Third Line',
96
'',
97
'123'
98
],
99
null,
100
true,
101
new Selection(1, 1, 1, 1),
102
[
103
'\tMy First Line',
104
'\t\tMy Second Line',
105
' Third Line',
106
'',
107
'123'
108
],
109
new Selection(1, 2, 1, 2)
110
);
111
});
112
113
test('shift on single line selection 1', () => {
114
testShiftCommand(
115
[
116
'My First Line',
117
'\t\tMy Second Line',
118
' Third Line',
119
'',
120
'123'
121
],
122
null,
123
true,
124
new Selection(1, 3, 1, 1),
125
[
126
'\tMy First Line',
127
'\t\tMy Second Line',
128
' Third Line',
129
'',
130
'123'
131
],
132
new Selection(1, 4, 1, 1)
133
);
134
});
135
136
test('shift on single line selection 2', () => {
137
testShiftCommand(
138
[
139
'My First Line',
140
'\t\tMy Second Line',
141
' Third Line',
142
'',
143
'123'
144
],
145
null,
146
true,
147
new Selection(1, 1, 1, 3),
148
[
149
'\tMy First Line',
150
'\t\tMy Second Line',
151
' Third Line',
152
'',
153
'123'
154
],
155
new Selection(1, 1, 1, 4)
156
);
157
});
158
159
test('simple shift', () => {
160
testShiftCommand(
161
[
162
'My First Line',
163
'\t\tMy Second Line',
164
' Third Line',
165
'',
166
'123'
167
],
168
null,
169
true,
170
new Selection(1, 1, 2, 1),
171
[
172
'\tMy First Line',
173
'\t\tMy Second Line',
174
' Third Line',
175
'',
176
'123'
177
],
178
new Selection(1, 1, 2, 1)
179
);
180
});
181
182
test('shifting on two separate lines', () => {
183
testShiftCommand(
184
[
185
'My First Line',
186
'\t\tMy Second Line',
187
' Third Line',
188
'',
189
'123'
190
],
191
null,
192
true,
193
new Selection(1, 1, 2, 1),
194
[
195
'\tMy First Line',
196
'\t\tMy Second Line',
197
' Third Line',
198
'',
199
'123'
200
],
201
new Selection(1, 1, 2, 1)
202
);
203
204
testShiftCommand(
205
[
206
'\tMy First Line',
207
'\t\tMy Second Line',
208
' Third Line',
209
'',
210
'123'
211
],
212
null,
213
true,
214
new Selection(2, 1, 3, 1),
215
[
216
'\tMy First Line',
217
'\t\t\tMy Second Line',
218
' Third Line',
219
'',
220
'123'
221
],
222
new Selection(2, 1, 3, 1)
223
);
224
});
225
226
test('shifting on two lines', () => {
227
testShiftCommand(
228
[
229
'My First Line',
230
'\t\tMy Second Line',
231
' Third Line',
232
'',
233
'123'
234
],
235
null,
236
true,
237
new Selection(1, 2, 2, 2),
238
[
239
'\tMy First Line',
240
'\t\t\tMy Second Line',
241
' Third Line',
242
'',
243
'123'
244
],
245
new Selection(1, 3, 2, 2)
246
);
247
});
248
249
test('shifting on two lines again', () => {
250
testShiftCommand(
251
[
252
'My First Line',
253
'\t\tMy Second Line',
254
' Third Line',
255
'',
256
'123'
257
],
258
null,
259
true,
260
new Selection(2, 2, 1, 2),
261
[
262
'\tMy First Line',
263
'\t\t\tMy Second Line',
264
' Third Line',
265
'',
266
'123'
267
],
268
new Selection(2, 2, 1, 3)
269
);
270
});
271
272
test('shifting at end of file', () => {
273
testShiftCommand(
274
[
275
'My First Line',
276
'\t\tMy Second Line',
277
' Third Line',
278
'',
279
'123'
280
],
281
null,
282
true,
283
new Selection(4, 1, 5, 2),
284
[
285
'My First Line',
286
'\t\tMy Second Line',
287
' Third Line',
288
'',
289
'\t123'
290
],
291
new Selection(4, 1, 5, 3)
292
);
293
});
294
295
test('issue #1120 TAB should not indent empty lines in a multi-line selection', () => {
296
testShiftCommand(
297
[
298
'My First Line',
299
'\t\tMy Second Line',
300
' Third Line',
301
'',
302
'123'
303
],
304
null,
305
true,
306
new Selection(1, 1, 5, 2),
307
[
308
'\tMy First Line',
309
'\t\t\tMy Second Line',
310
'\t\tThird Line',
311
'',
312
'\t123'
313
],
314
new Selection(1, 1, 5, 3)
315
);
316
317
testShiftCommand(
318
[
319
'My First Line',
320
'\t\tMy Second Line',
321
' Third Line',
322
'',
323
'123'
324
],
325
null,
326
true,
327
new Selection(4, 1, 5, 1),
328
[
329
'My First Line',
330
'\t\tMy Second Line',
331
' Third Line',
332
'\t',
333
'123'
334
],
335
new Selection(4, 1, 5, 1)
336
);
337
});
338
339
// --------- unshift
340
341
test('unshift on single line selection 1', () => {
342
testShiftCommand(
343
[
344
'My First Line',
345
'\t\tMy Second Line',
346
' Third Line',
347
'',
348
'123'
349
],
350
null,
351
true,
352
new Selection(2, 3, 2, 1),
353
[
354
'My First Line',
355
'\t\t\tMy Second Line',
356
' Third Line',
357
'',
358
'123'
359
],
360
new Selection(2, 3, 2, 1)
361
);
362
});
363
364
test('unshift on single line selection 2', () => {
365
testShiftCommand(
366
[
367
'My First Line',
368
'\t\tMy Second Line',
369
' Third Line',
370
'',
371
'123'
372
],
373
null,
374
true,
375
new Selection(2, 1, 2, 3),
376
[
377
'My First Line',
378
'\t\t\tMy Second Line',
379
' Third Line',
380
'',
381
'123'
382
],
383
new Selection(2, 1, 2, 3)
384
);
385
});
386
387
test('simple unshift', () => {
388
testUnshiftCommand(
389
[
390
'My First Line',
391
'\t\tMy Second Line',
392
' Third Line',
393
'',
394
'123'
395
],
396
null,
397
true,
398
new Selection(1, 1, 2, 1),
399
[
400
'My First Line',
401
'\t\tMy Second Line',
402
' Third Line',
403
'',
404
'123'
405
],
406
new Selection(1, 1, 2, 1)
407
);
408
});
409
410
test('unshifting on two lines 1', () => {
411
testUnshiftCommand(
412
[
413
'My First Line',
414
'\t\tMy Second Line',
415
' Third Line',
416
'',
417
'123'
418
],
419
null,
420
true,
421
new Selection(1, 2, 2, 2),
422
[
423
'My First Line',
424
'\tMy Second Line',
425
' Third Line',
426
'',
427
'123'
428
],
429
new Selection(1, 2, 2, 2)
430
);
431
});
432
433
test('unshifting on two lines 2', () => {
434
testUnshiftCommand(
435
[
436
'My First Line',
437
'\t\tMy Second Line',
438
' Third Line',
439
'',
440
'123'
441
],
442
null,
443
true,
444
new Selection(2, 3, 2, 1),
445
[
446
'My First Line',
447
'\tMy Second Line',
448
' Third Line',
449
'',
450
'123'
451
],
452
new Selection(2, 2, 2, 1)
453
);
454
});
455
456
test('unshifting at the end of the file', () => {
457
testUnshiftCommand(
458
[
459
'My First Line',
460
'\t\tMy Second Line',
461
' Third Line',
462
'',
463
'123'
464
],
465
null,
466
true,
467
new Selection(4, 1, 5, 2),
468
[
469
'My First Line',
470
'\t\tMy Second Line',
471
' Third Line',
472
'',
473
'123'
474
],
475
new Selection(4, 1, 5, 2)
476
);
477
});
478
479
test('unshift many times + shift', () => {
480
testUnshiftCommand(
481
[
482
'My First Line',
483
'\t\tMy Second Line',
484
' Third Line',
485
'',
486
'123'
487
],
488
null,
489
true,
490
new Selection(1, 1, 5, 4),
491
[
492
'My First Line',
493
'\tMy Second Line',
494
'Third Line',
495
'',
496
'123'
497
],
498
new Selection(1, 1, 5, 4)
499
);
500
501
testUnshiftCommand(
502
[
503
'My First Line',
504
'\tMy Second Line',
505
'Third Line',
506
'',
507
'123'
508
],
509
null,
510
true,
511
new Selection(1, 1, 5, 4),
512
[
513
'My First Line',
514
'My Second Line',
515
'Third Line',
516
'',
517
'123'
518
],
519
new Selection(1, 1, 5, 4)
520
);
521
522
testShiftCommand(
523
[
524
'My First Line',
525
'My Second Line',
526
'Third Line',
527
'',
528
'123'
529
],
530
null,
531
true,
532
new Selection(1, 1, 5, 4),
533
[
534
'\tMy First Line',
535
'\tMy Second Line',
536
'\tThird Line',
537
'',
538
'\t123'
539
],
540
new Selection(1, 1, 5, 5)
541
);
542
});
543
544
test('Bug 9119: Unshift from first column doesn\'t work', () => {
545
testUnshiftCommand(
546
[
547
'My First Line',
548
'\t\tMy Second Line',
549
' Third Line',
550
'',
551
'123'
552
],
553
null,
554
true,
555
new Selection(2, 1, 2, 1),
556
[
557
'My First Line',
558
'\tMy Second Line',
559
' Third Line',
560
'',
561
'123'
562
],
563
new Selection(2, 1, 2, 1)
564
);
565
});
566
567
test('issue #348: indenting around doc block comments', () => {
568
testShiftCommand(
569
[
570
'',
571
'/**',
572
' * a doc comment',
573
' */',
574
'function hello() {}'
575
],
576
DocBlockCommentMode.languageId,
577
true,
578
new Selection(1, 1, 5, 20),
579
[
580
'',
581
'\t/**',
582
'\t * a doc comment',
583
'\t */',
584
'\tfunction hello() {}'
585
],
586
new Selection(1, 1, 5, 21),
587
prepareDocBlockCommentLanguage
588
);
589
590
testUnshiftCommand(
591
[
592
'',
593
'/**',
594
' * a doc comment',
595
' */',
596
'function hello() {}'
597
],
598
DocBlockCommentMode.languageId,
599
true,
600
new Selection(1, 1, 5, 20),
601
[
602
'',
603
'/**',
604
' * a doc comment',
605
' */',
606
'function hello() {}'
607
],
608
new Selection(1, 1, 5, 20),
609
prepareDocBlockCommentLanguage
610
);
611
612
testUnshiftCommand(
613
[
614
'\t',
615
'\t/**',
616
'\t * a doc comment',
617
'\t */',
618
'\tfunction hello() {}'
619
],
620
DocBlockCommentMode.languageId,
621
true,
622
new Selection(1, 1, 5, 21),
623
[
624
'',
625
'/**',
626
' * a doc comment',
627
' */',
628
'function hello() {}'
629
],
630
new Selection(1, 1, 5, 20),
631
prepareDocBlockCommentLanguage
632
);
633
});
634
635
test('issue #1609: Wrong indentation of block comments', () => {
636
testShiftCommand(
637
[
638
'',
639
'/**',
640
' * test',
641
' *',
642
' * @type {number}',
643
' */',
644
'var foo = 0;'
645
],
646
DocBlockCommentMode.languageId,
647
true,
648
new Selection(1, 1, 7, 13),
649
[
650
'',
651
'\t/**',
652
'\t * test',
653
'\t *',
654
'\t * @type {number}',
655
'\t */',
656
'\tvar foo = 0;'
657
],
658
new Selection(1, 1, 7, 14),
659
prepareDocBlockCommentLanguage
660
);
661
});
662
663
test('issue #1620: a) Line indent doesn\'t handle leading whitespace properly', () => {
664
testCommand(
665
[
666
' Written | Numeric',
667
' one | 1',
668
' two | 2',
669
' three | 3',
670
' four | 4',
671
' five | 5',
672
' six | 6',
673
' seven | 7',
674
' eight | 8',
675
' nine | 9',
676
' ten | 10',
677
' eleven | 11',
678
'',
679
],
680
null,
681
new Selection(1, 1, 13, 1),
682
(accessor, sel) => new ShiftCommand(sel, {
683
isUnshift: false,
684
tabSize: 4,
685
indentSize: 4,
686
insertSpaces: true,
687
useTabStops: false,
688
autoIndent: EditorAutoIndentStrategy.Full,
689
}, accessor.get(ILanguageConfigurationService)),
690
[
691
' Written | Numeric',
692
' one | 1',
693
' two | 2',
694
' three | 3',
695
' four | 4',
696
' five | 5',
697
' six | 6',
698
' seven | 7',
699
' eight | 8',
700
' nine | 9',
701
' ten | 10',
702
' eleven | 11',
703
'',
704
],
705
new Selection(1, 1, 13, 1)
706
);
707
});
708
709
test('issue #1620: b) Line indent doesn\'t handle leading whitespace properly', () => {
710
testCommand(
711
[
712
' Written | Numeric',
713
' one | 1',
714
' two | 2',
715
' three | 3',
716
' four | 4',
717
' five | 5',
718
' six | 6',
719
' seven | 7',
720
' eight | 8',
721
' nine | 9',
722
' ten | 10',
723
' eleven | 11',
724
'',
725
],
726
null,
727
new Selection(1, 1, 13, 1),
728
(accessor, sel) => new ShiftCommand(sel, {
729
isUnshift: true,
730
tabSize: 4,
731
indentSize: 4,
732
insertSpaces: true,
733
useTabStops: false,
734
autoIndent: EditorAutoIndentStrategy.Full,
735
}, accessor.get(ILanguageConfigurationService)),
736
[
737
' Written | Numeric',
738
' one | 1',
739
' two | 2',
740
' three | 3',
741
' four | 4',
742
' five | 5',
743
' six | 6',
744
' seven | 7',
745
' eight | 8',
746
' nine | 9',
747
' ten | 10',
748
' eleven | 11',
749
'',
750
],
751
new Selection(1, 1, 13, 1)
752
);
753
});
754
755
test('issue #1620: c) Line indent doesn\'t handle leading whitespace properly', () => {
756
testCommand(
757
[
758
' Written | Numeric',
759
' one | 1',
760
' two | 2',
761
' three | 3',
762
' four | 4',
763
' five | 5',
764
' six | 6',
765
' seven | 7',
766
' eight | 8',
767
' nine | 9',
768
' ten | 10',
769
' eleven | 11',
770
'',
771
],
772
null,
773
new Selection(1, 1, 13, 1),
774
(accessor, sel) => new ShiftCommand(sel, {
775
isUnshift: true,
776
tabSize: 4,
777
indentSize: 4,
778
insertSpaces: false,
779
useTabStops: false,
780
autoIndent: EditorAutoIndentStrategy.Full,
781
}, accessor.get(ILanguageConfigurationService)),
782
[
783
' Written | Numeric',
784
' one | 1',
785
' two | 2',
786
' three | 3',
787
' four | 4',
788
' five | 5',
789
' six | 6',
790
' seven | 7',
791
' eight | 8',
792
' nine | 9',
793
' ten | 10',
794
' eleven | 11',
795
'',
796
],
797
new Selection(1, 1, 13, 1)
798
);
799
});
800
801
test('issue #1620: d) Line indent doesn\'t handle leading whitespace properly', () => {
802
testCommand(
803
[
804
'\t Written | Numeric',
805
'\t one | 1',
806
'\t two | 2',
807
'\t three | 3',
808
'\t four | 4',
809
'\t five | 5',
810
'\t six | 6',
811
'\t seven | 7',
812
'\t eight | 8',
813
'\t nine | 9',
814
'\t ten | 10',
815
'\t eleven | 11',
816
'',
817
],
818
null,
819
new Selection(1, 1, 13, 1),
820
(accessor, sel) => new ShiftCommand(sel, {
821
isUnshift: true,
822
tabSize: 4,
823
indentSize: 4,
824
insertSpaces: true,
825
useTabStops: false,
826
autoIndent: EditorAutoIndentStrategy.Full,
827
}, accessor.get(ILanguageConfigurationService)),
828
[
829
' Written | Numeric',
830
' one | 1',
831
' two | 2',
832
' three | 3',
833
' four | 4',
834
' five | 5',
835
' six | 6',
836
' seven | 7',
837
' eight | 8',
838
' nine | 9',
839
' ten | 10',
840
' eleven | 11',
841
'',
842
],
843
new Selection(1, 1, 13, 1)
844
);
845
});
846
847
test('issue microsoft/monaco-editor#443: Indentation of a single row deletes selected text in some cases', () => {
848
testCommand(
849
[
850
'Hello world!',
851
'another line'
852
],
853
null,
854
new Selection(1, 1, 1, 13),
855
(accessor, sel) => new ShiftCommand(sel, {
856
isUnshift: false,
857
tabSize: 4,
858
indentSize: 4,
859
insertSpaces: false,
860
useTabStops: true,
861
autoIndent: EditorAutoIndentStrategy.Full,
862
}, accessor.get(ILanguageConfigurationService)),
863
[
864
'\tHello world!',
865
'another line'
866
],
867
new Selection(1, 1, 1, 14)
868
);
869
});
870
871
test('bug #16815:Shift+Tab doesn\'t go back to tabstop', () => {
872
873
const repeatStr = (str: string, cnt: number): string => {
874
let r = '';
875
for (let i = 0; i < cnt; i++) {
876
r += str;
877
}
878
return r;
879
};
880
881
const testOutdent = (tabSize: number, indentSize: number, insertSpaces: boolean, lineText: string, expectedIndents: number) => {
882
const oneIndent = insertSpaces ? repeatStr(' ', indentSize) : '\t';
883
const expectedIndent = repeatStr(oneIndent, expectedIndents);
884
if (lineText.length > 0) {
885
_assertUnshiftCommand(tabSize, indentSize, insertSpaces, [lineText + 'aaa'], [createSingleEditOp(expectedIndent, 1, 1, 1, lineText.length + 1)]);
886
} else {
887
_assertUnshiftCommand(tabSize, indentSize, insertSpaces, [lineText + 'aaa'], []);
888
}
889
};
890
891
const testIndent = (tabSize: number, indentSize: number, insertSpaces: boolean, lineText: string, expectedIndents: number) => {
892
const oneIndent = insertSpaces ? repeatStr(' ', indentSize) : '\t';
893
const expectedIndent = repeatStr(oneIndent, expectedIndents);
894
_assertShiftCommand(tabSize, indentSize, insertSpaces, [lineText + 'aaa'], [createSingleEditOp(expectedIndent, 1, 1, 1, lineText.length + 1)]);
895
};
896
897
const testIndentation = (tabSize: number, indentSize: number, lineText: string, expectedOnOutdent: number, expectedOnIndent: number) => {
898
testOutdent(tabSize, indentSize, true, lineText, expectedOnOutdent);
899
testOutdent(tabSize, indentSize, false, lineText, expectedOnOutdent);
900
901
testIndent(tabSize, indentSize, true, lineText, expectedOnIndent);
902
testIndent(tabSize, indentSize, false, lineText, expectedOnIndent);
903
};
904
905
// insertSpaces: true
906
// 0 => 0
907
testIndentation(4, 4, '', 0, 1);
908
909
// 1 => 0
910
testIndentation(4, 4, '\t', 0, 2);
911
testIndentation(4, 4, ' ', 0, 1);
912
testIndentation(4, 4, ' \t', 0, 2);
913
testIndentation(4, 4, ' ', 0, 1);
914
testIndentation(4, 4, ' \t', 0, 2);
915
testIndentation(4, 4, ' ', 0, 1);
916
testIndentation(4, 4, ' \t', 0, 2);
917
testIndentation(4, 4, ' ', 0, 2);
918
919
// 2 => 1
920
testIndentation(4, 4, '\t\t', 1, 3);
921
testIndentation(4, 4, '\t ', 1, 2);
922
testIndentation(4, 4, '\t \t', 1, 3);
923
testIndentation(4, 4, '\t ', 1, 2);
924
testIndentation(4, 4, '\t \t', 1, 3);
925
testIndentation(4, 4, '\t ', 1, 2);
926
testIndentation(4, 4, '\t \t', 1, 3);
927
testIndentation(4, 4, '\t ', 1, 3);
928
testIndentation(4, 4, ' \t\t', 1, 3);
929
testIndentation(4, 4, ' \t ', 1, 2);
930
testIndentation(4, 4, ' \t \t', 1, 3);
931
testIndentation(4, 4, ' \t ', 1, 2);
932
testIndentation(4, 4, ' \t \t', 1, 3);
933
testIndentation(4, 4, ' \t ', 1, 2);
934
testIndentation(4, 4, ' \t \t', 1, 3);
935
testIndentation(4, 4, ' \t ', 1, 3);
936
testIndentation(4, 4, ' \t\t', 1, 3);
937
testIndentation(4, 4, ' \t ', 1, 2);
938
testIndentation(4, 4, ' \t \t', 1, 3);
939
testIndentation(4, 4, ' \t ', 1, 2);
940
testIndentation(4, 4, ' \t \t', 1, 3);
941
testIndentation(4, 4, ' \t ', 1, 2);
942
testIndentation(4, 4, ' \t \t', 1, 3);
943
testIndentation(4, 4, ' \t ', 1, 3);
944
testIndentation(4, 4, ' \t\t', 1, 3);
945
testIndentation(4, 4, ' \t ', 1, 2);
946
testIndentation(4, 4, ' \t \t', 1, 3);
947
testIndentation(4, 4, ' \t ', 1, 2);
948
testIndentation(4, 4, ' \t \t', 1, 3);
949
testIndentation(4, 4, ' \t ', 1, 2);
950
testIndentation(4, 4, ' \t \t', 1, 3);
951
testIndentation(4, 4, ' \t ', 1, 3);
952
testIndentation(4, 4, ' \t', 1, 3);
953
testIndentation(4, 4, ' ', 1, 2);
954
testIndentation(4, 4, ' \t', 1, 3);
955
testIndentation(4, 4, ' ', 1, 2);
956
testIndentation(4, 4, ' \t', 1, 3);
957
testIndentation(4, 4, ' ', 1, 2);
958
testIndentation(4, 4, ' \t', 1, 3);
959
testIndentation(4, 4, ' ', 1, 3);
960
961
// 3 => 2
962
testIndentation(4, 4, ' ', 2, 3);
963
964
function _assertUnshiftCommand(tabSize: number, indentSize: number, insertSpaces: boolean, text: string[], expected: ISingleEditOperation[]): void {
965
return withEditorModel(text, (model) => {
966
const testLanguageConfigurationService = new TestLanguageConfigurationService();
967
const op = new ShiftCommand(new Selection(1, 1, text.length + 1, 1), {
968
isUnshift: true,
969
tabSize: tabSize,
970
indentSize: indentSize,
971
insertSpaces: insertSpaces,
972
useTabStops: true,
973
autoIndent: EditorAutoIndentStrategy.Full,
974
}, testLanguageConfigurationService);
975
const actual = getEditOperation(model, op);
976
assert.deepStrictEqual(actual, expected);
977
testLanguageConfigurationService.dispose();
978
});
979
}
980
981
function _assertShiftCommand(tabSize: number, indentSize: number, insertSpaces: boolean, text: string[], expected: ISingleEditOperation[]): void {
982
return withEditorModel(text, (model) => {
983
const testLanguageConfigurationService = new TestLanguageConfigurationService();
984
const op = new ShiftCommand(new Selection(1, 1, text.length + 1, 1), {
985
isUnshift: false,
986
tabSize: tabSize,
987
indentSize: indentSize,
988
insertSpaces: insertSpaces,
989
useTabStops: true,
990
autoIndent: EditorAutoIndentStrategy.Full,
991
}, testLanguageConfigurationService);
992
const actual = getEditOperation(model, op);
993
assert.deepStrictEqual(actual, expected);
994
testLanguageConfigurationService.dispose();
995
});
996
}
997
});
998
999
});
1000
1001