Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/find/test/browser/findController.test.ts
4780 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 { Delayer } from '../../../../../base/common/async.js';
8
import * as platform from '../../../../../base/common/platform.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
10
import { ICodeEditor } from '../../../../browser/editorBrowser.js';
11
import { EditorAction } from '../../../../browser/editorExtensions.js';
12
import { EditOperation } from '../../../../common/core/editOperation.js';
13
import { Position } from '../../../../common/core/position.js';
14
import { Range } from '../../../../common/core/range.js';
15
import { Selection } from '../../../../common/core/selection.js';
16
import { CommonFindController, FindStartFocusAction, IFindStartOptions, NextMatchFindAction, NextSelectionMatchFindAction, StartFindAction, StartFindReplaceAction, StartFindWithSelectionAction } from '../../browser/findController.js';
17
import { CONTEXT_FIND_INPUT_FOCUSED } from '../../browser/findModel.js';
18
import { withAsyncTestCodeEditor } from '../../../../test/browser/testCodeEditor.js';
19
import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js';
20
import { IContextKey, IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
21
import { IHoverService } from '../../../../../platform/hover/browser/hover.js';
22
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
23
import { ServiceCollection } from '../../../../../platform/instantiation/common/serviceCollection.js';
24
import { INotificationService } from '../../../../../platform/notification/common/notification.js';
25
import { IStorageService, InMemoryStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
26
27
class TestFindController extends CommonFindController {
28
29
public hasFocus: boolean;
30
public delayUpdateHistory: boolean = false;
31
32
private _findInputFocused: IContextKey<boolean>;
33
34
constructor(
35
editor: ICodeEditor,
36
@IContextKeyService contextKeyService: IContextKeyService,
37
@IStorageService storageService: IStorageService,
38
@IClipboardService clipboardService: IClipboardService,
39
@INotificationService notificationService: INotificationService,
40
@IHoverService hoverService: IHoverService
41
) {
42
super(editor, contextKeyService, storageService, clipboardService, notificationService, hoverService);
43
this._findInputFocused = CONTEXT_FIND_INPUT_FOCUSED.bindTo(contextKeyService);
44
this._updateHistoryDelayer = new Delayer<void>(50);
45
this.hasFocus = false;
46
}
47
48
protected override async _start(opts: IFindStartOptions): Promise<void> {
49
await super._start(opts);
50
51
if (opts.shouldFocus !== FindStartFocusAction.NoFocusChange) {
52
this.hasFocus = true;
53
}
54
55
const inputFocused = opts.shouldFocus === FindStartFocusAction.FocusFindInput;
56
this._findInputFocused.set(inputFocused);
57
}
58
}
59
60
function fromSelection(slc: Selection): number[] {
61
return [slc.startLineNumber, slc.startColumn, slc.endLineNumber, slc.endColumn];
62
}
63
64
function executeAction(instantiationService: IInstantiationService, editor: ICodeEditor, action: EditorAction, args?: any): Promise<void> {
65
return instantiationService.invokeFunction((accessor) => {
66
return Promise.resolve(action.runEditorCommand(accessor, editor, args));
67
});
68
}
69
70
suite('FindController', () => {
71
72
ensureNoDisposablesAreLeakedInTestSuite();
73
74
let clipboardState = '';
75
const serviceCollection = new ServiceCollection();
76
serviceCollection.set(IStorageService, new InMemoryStorageService());
77
78
if (platform.isMacintosh) {
79
// eslint-disable-next-line local/code-no-any-casts
80
serviceCollection.set(IClipboardService, <any>{
81
readFindText: () => clipboardState,
82
writeFindText: (value: any) => { clipboardState = value; }
83
});
84
}
85
86
/* test('stores to the global clipboard buffer on start find action', async () => {
87
await withAsyncTestCodeEditor([
88
'ABC',
89
'ABC',
90
'XYZ',
91
'ABC'
92
], { serviceCollection: serviceCollection }, async (editor) => {
93
clipboardState = '';
94
if (!platform.isMacintosh) {
95
assert.ok(true);
96
return;
97
}
98
let findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
99
let startFindAction = new StartFindAction();
100
// I select ABC on the first line
101
editor.setSelection(new Selection(1, 1, 1, 4));
102
// I hit Ctrl+F to show the Find dialog
103
startFindAction.run(null, editor);
104
105
assert.deepStrictEqual(findController.getGlobalBufferTerm(), findController.getState().searchString);
106
findController.dispose();
107
});
108
});
109
110
test('reads from the global clipboard buffer on next find action if buffer exists', async () => {
111
await withAsyncTestCodeEditor([
112
'ABC',
113
'ABC',
114
'XYZ',
115
'ABC'
116
], { serviceCollection: serviceCollection }, async (editor) => {
117
clipboardState = 'ABC';
118
119
if (!platform.isMacintosh) {
120
assert.ok(true);
121
return;
122
}
123
124
let findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
125
let findState = findController.getState();
126
let nextMatchFindAction = new NextMatchFindAction();
127
128
nextMatchFindAction.run(null, editor);
129
assert.strictEqual(findState.searchString, 'ABC');
130
131
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
132
133
findController.dispose();
134
});
135
});
136
137
test('writes to the global clipboard buffer when text changes', async () => {
138
await withAsyncTestCodeEditor([
139
'ABC',
140
'ABC',
141
'XYZ',
142
'ABC'
143
], { serviceCollection: serviceCollection }, async (editor) => {
144
clipboardState = '';
145
if (!platform.isMacintosh) {
146
assert.ok(true);
147
return;
148
}
149
150
let findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
151
let findState = findController.getState();
152
153
findState.change({ searchString: 'ABC' }, true);
154
155
assert.deepStrictEqual(findController.getGlobalBufferTerm(), 'ABC');
156
157
findController.dispose();
158
});
159
}); */
160
161
test('issue #1857: F3, Find Next, acts like "Find Under Cursor"', async () => {
162
await withAsyncTestCodeEditor([
163
'ABC',
164
'ABC',
165
'XYZ',
166
'ABC'
167
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
168
clipboardState = '';
169
// The cursor is at the very top, of the file, at the first ABC
170
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
171
const findState = findController.getState();
172
const nextMatchFindAction = NextMatchFindAction;
173
174
// I hit Ctrl+F to show the Find dialog
175
await executeAction(instantiationService, editor, StartFindAction);
176
177
// I type ABC.
178
findState.change({ searchString: 'A' }, true);
179
findState.change({ searchString: 'AB' }, true);
180
findState.change({ searchString: 'ABC' }, true);
181
182
// The first ABC is highlighted.
183
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
184
185
// I hit Esc to exit the Find dialog.
186
findController.closeFindWidget();
187
findController.hasFocus = false;
188
189
// The cursor is now at end of the first line, with ABC on that line highlighted.
190
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
191
192
// I hit delete to remove it and change the text to XYZ.
193
editor.pushUndoStop();
194
editor.executeEdits('test', [EditOperation.delete(new Range(1, 1, 1, 4))]);
195
editor.executeEdits('test', [EditOperation.insert(new Position(1, 1), 'XYZ')]);
196
editor.pushUndoStop();
197
198
// At this point the text editor looks like this:
199
// XYZ
200
// ABC
201
// XYZ
202
// ABC
203
assert.strictEqual(editor.getModel()!.getLineContent(1), 'XYZ');
204
205
// The cursor is at end of the first line.
206
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 4, 1, 4]);
207
208
// I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
209
await editor.runAction(nextMatchFindAction);
210
211
assert.strictEqual(findState.searchString, 'ABC');
212
assert.strictEqual(findController.hasFocus, false);
213
214
findController.dispose();
215
});
216
});
217
218
test('issue #3090: F3 does not loop with two matches on a single line', async () => {
219
await withAsyncTestCodeEditor([
220
'import nls = require(\'vs/nls\');'
221
], { serviceCollection: serviceCollection }, async (editor) => {
222
clipboardState = '';
223
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
224
const nextMatchFindAction = NextMatchFindAction;
225
226
editor.setPosition({
227
lineNumber: 1,
228
column: 9
229
});
230
231
await editor.runAction(nextMatchFindAction);
232
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 26, 1, 29]);
233
234
await editor.runAction(nextMatchFindAction);
235
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 8, 1, 11]);
236
237
findController.dispose();
238
});
239
});
240
241
test('issue #6149: Auto-escape highlighted text for search and replace regex mode', async () => {
242
await withAsyncTestCodeEditor([
243
'var x = (3 * 5)',
244
'var y = (3 * 5)',
245
'var z = (3 * 5)',
246
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
247
clipboardState = '';
248
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
249
const nextMatchFindAction = NextMatchFindAction;
250
251
editor.setSelection(new Selection(1, 9, 1, 13));
252
253
findController.toggleRegex();
254
await executeAction(instantiationService, editor, StartFindAction);
255
256
await editor.runAction(nextMatchFindAction);
257
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [2, 9, 2, 13]);
258
259
await editor.runAction(nextMatchFindAction);
260
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 9, 1, 13]);
261
262
findController.dispose();
263
});
264
});
265
266
test('issue #41027: Don\'t replace find input value on replace action if find input is active', async () => {
267
await withAsyncTestCodeEditor([
268
'test',
269
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
270
const testRegexString = 'tes.';
271
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
272
const nextMatchFindAction = NextMatchFindAction;
273
274
findController.toggleRegex();
275
findController.setSearchString(testRegexString);
276
await findController.start({
277
forceRevealReplace: false,
278
seedSearchStringFromSelection: 'none',
279
seedSearchStringFromNonEmptySelection: false,
280
seedSearchStringFromGlobalClipboard: false,
281
shouldFocus: FindStartFocusAction.FocusFindInput,
282
shouldAnimate: false,
283
updateSearchScope: false,
284
loop: true
285
});
286
await editor.runAction(nextMatchFindAction);
287
await executeAction(instantiationService, editor, StartFindReplaceAction);
288
289
assert.strictEqual(findController.getState().searchString, testRegexString);
290
291
findController.dispose();
292
});
293
});
294
295
test('issue #9043: Clear search scope when find widget is hidden', async () => {
296
await withAsyncTestCodeEditor([
297
'var x = (3 * 5)',
298
'var y = (3 * 5)',
299
'var z = (3 * 5)',
300
], { serviceCollection: serviceCollection }, async (editor) => {
301
clipboardState = '';
302
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
303
await findController.start({
304
forceRevealReplace: false,
305
seedSearchStringFromSelection: 'none',
306
seedSearchStringFromNonEmptySelection: false,
307
seedSearchStringFromGlobalClipboard: false,
308
shouldFocus: FindStartFocusAction.NoFocusChange,
309
shouldAnimate: false,
310
updateSearchScope: false,
311
loop: true
312
});
313
314
assert.strictEqual(findController.getState().searchScope, null);
315
316
findController.getState().change({
317
searchScope: [new Range(1, 1, 1, 5)]
318
}, false);
319
320
assert.deepStrictEqual(findController.getState().searchScope, [new Range(1, 1, 1, 5)]);
321
322
findController.closeFindWidget();
323
assert.strictEqual(findController.getState().searchScope, null);
324
});
325
});
326
327
test('issue #18111: Regex replace with single space replaces with no space', async () => {
328
await withAsyncTestCodeEditor([
329
'HRESULT OnAmbientPropertyChange(DISPID dispid);'
330
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
331
clipboardState = '';
332
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
333
334
await executeAction(instantiationService, editor, StartFindAction);
335
336
findController.getState().change({ searchString: '\\b\\s{3}\\b', replaceString: ' ', isRegex: true }, false);
337
findController.moveToNextMatch();
338
339
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
340
[1, 39, 1, 42]
341
]);
342
343
findController.replace();
344
345
assert.deepStrictEqual(editor.getValue(), 'HRESULT OnAmbientPropertyChange(DISPID dispid);');
346
347
findController.dispose();
348
});
349
});
350
351
test('issue #24714: Regular expression with ^ in search & replace', async () => {
352
await withAsyncTestCodeEditor([
353
'',
354
'line2',
355
'line3'
356
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
357
clipboardState = '';
358
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
359
360
await executeAction(instantiationService, editor, StartFindAction);
361
362
findController.getState().change({ searchString: '^', replaceString: 'x', isRegex: true }, false);
363
findController.moveToNextMatch();
364
365
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
366
[2, 1, 2, 1]
367
]);
368
369
findController.replace();
370
371
assert.deepStrictEqual(editor.getValue(), '\nxline2\nline3');
372
373
findController.dispose();
374
});
375
});
376
377
test('issue #38232: Find Next Selection, regex enabled', async () => {
378
await withAsyncTestCodeEditor([
379
'([funny]',
380
'',
381
'([funny]'
382
], { serviceCollection: serviceCollection }, async (editor) => {
383
clipboardState = '';
384
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
385
const nextSelectionMatchFindAction = new NextSelectionMatchFindAction();
386
387
// toggle regex
388
findController.getState().change({ isRegex: true }, false);
389
390
// change selection
391
editor.setSelection(new Selection(1, 1, 1, 9));
392
393
// cmd+f3
394
await editor.runAction(nextSelectionMatchFindAction);
395
396
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
397
[3, 1, 3, 9]
398
]);
399
400
findController.dispose();
401
});
402
});
403
404
test('issue #38232: Find Next Selection, regex enabled, find widget open', async () => {
405
await withAsyncTestCodeEditor([
406
'([funny]',
407
'',
408
'([funny]'
409
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
410
clipboardState = '';
411
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
412
const nextSelectionMatchFindAction = new NextSelectionMatchFindAction();
413
414
// cmd+f - open find widget
415
await executeAction(instantiationService, editor, StartFindAction);
416
417
// toggle regex
418
findController.getState().change({ isRegex: true }, false);
419
420
// change selection
421
editor.setSelection(new Selection(1, 1, 1, 9));
422
423
// cmd+f3
424
await editor.runAction(nextSelectionMatchFindAction);
425
426
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
427
[3, 1, 3, 9]
428
]);
429
430
findController.dispose();
431
});
432
});
433
434
test('issue #47400, CMD+E supports feeding multiple line of text into the find widget', async () => {
435
await withAsyncTestCodeEditor([
436
'ABC',
437
'ABC',
438
'XYZ',
439
'ABC',
440
'ABC'
441
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
442
clipboardState = '';
443
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
444
445
// change selection
446
editor.setSelection(new Selection(1, 1, 1, 1));
447
448
// cmd+f - open find widget
449
await executeAction(instantiationService, editor, StartFindAction);
450
451
editor.setSelection(new Selection(1, 1, 2, 4));
452
const startFindWithSelectionAction = new StartFindWithSelectionAction();
453
await editor.runAction(startFindWithSelectionAction);
454
const findState = findController.getState();
455
456
assert.deepStrictEqual(findState.searchString.split(/\r\n|\r|\n/g), ['ABC', 'ABC']);
457
458
editor.setSelection(new Selection(3, 1, 3, 1));
459
await editor.runAction(startFindWithSelectionAction);
460
461
findController.dispose();
462
});
463
});
464
465
test('issue #109756, CMD+E with empty cursor should always work', async () => {
466
await withAsyncTestCodeEditor([
467
'ABC',
468
'ABC',
469
'XYZ',
470
'ABC',
471
'ABC'
472
], { serviceCollection: serviceCollection }, async (editor) => {
473
clipboardState = '';
474
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
475
editor.setSelection(new Selection(1, 2, 1, 2));
476
477
const startFindWithSelectionAction = new StartFindWithSelectionAction();
478
editor.runAction(startFindWithSelectionAction);
479
480
const findState = findController.getState();
481
assert.deepStrictEqual(findState.searchString, 'ABC');
482
findController.dispose();
483
});
484
});
485
});
486
487
suite('FindController query options persistence', () => {
488
489
ensureNoDisposablesAreLeakedInTestSuite();
490
491
const serviceCollection = new ServiceCollection();
492
const storageService = new InMemoryStorageService();
493
storageService.store('editor.isRegex', false, StorageScope.WORKSPACE, StorageTarget.USER);
494
storageService.store('editor.matchCase', false, StorageScope.WORKSPACE, StorageTarget.USER);
495
storageService.store('editor.wholeWord', false, StorageScope.WORKSPACE, StorageTarget.USER);
496
serviceCollection.set(IStorageService, storageService);
497
498
test('matchCase', async () => {
499
await withAsyncTestCodeEditor([
500
'abc',
501
'ABC',
502
'XYZ',
503
'ABC'
504
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
505
storageService.store('editor.matchCase', true, StorageScope.WORKSPACE, StorageTarget.USER);
506
// The cursor is at the very top, of the file, at the first ABC
507
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
508
const findState = findController.getState();
509
510
// I hit Ctrl+F to show the Find dialog
511
await executeAction(instantiationService, editor, StartFindAction);
512
513
// I type ABC.
514
findState.change({ searchString: 'ABC' }, true);
515
// The second ABC is highlighted as matchCase is true.
516
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [2, 1, 2, 4]);
517
518
findController.dispose();
519
});
520
});
521
522
storageService.store('editor.matchCase', false, StorageScope.WORKSPACE, StorageTarget.USER);
523
storageService.store('editor.wholeWord', true, StorageScope.WORKSPACE, StorageTarget.USER);
524
525
test('wholeWord', async () => {
526
await withAsyncTestCodeEditor([
527
'ABC',
528
'AB',
529
'XYZ',
530
'ABC'
531
], { serviceCollection: serviceCollection }, async (editor, _, instantiationService) => {
532
// The cursor is at the very top, of the file, at the first ABC
533
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
534
const findState = findController.getState();
535
536
// I hit Ctrl+F to show the Find dialog
537
await executeAction(instantiationService, editor, StartFindAction);
538
539
// I type AB.
540
findState.change({ searchString: 'AB' }, true);
541
// The second AB is highlighted as wholeWord is true.
542
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [2, 1, 2, 3]);
543
544
findController.dispose();
545
});
546
});
547
548
test('toggling options is saved', async () => {
549
await withAsyncTestCodeEditor([
550
'ABC',
551
'AB',
552
'XYZ',
553
'ABC'
554
], { serviceCollection: serviceCollection }, async (editor) => {
555
// The cursor is at the very top, of the file, at the first ABC
556
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
557
findController.toggleRegex();
558
assert.strictEqual(storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE), true);
559
560
findController.dispose();
561
});
562
});
563
564
test('issue #27083: Update search scope once find widget becomes visible', async () => {
565
await withAsyncTestCodeEditor([
566
'var x = (3 * 5)',
567
'var y = (3 * 5)',
568
'var z = (3 * 5)',
569
], { serviceCollection: serviceCollection, find: { autoFindInSelection: 'always', globalFindClipboard: false } }, async (editor) => {
570
// clipboardState = '';
571
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
572
const findConfig: IFindStartOptions = {
573
forceRevealReplace: false,
574
seedSearchStringFromSelection: 'none',
575
seedSearchStringFromNonEmptySelection: false,
576
seedSearchStringFromGlobalClipboard: false,
577
shouldFocus: FindStartFocusAction.NoFocusChange,
578
shouldAnimate: false,
579
updateSearchScope: true,
580
loop: true
581
};
582
583
editor.setSelection(new Range(1, 1, 2, 1));
584
findController.start(findConfig);
585
assert.deepStrictEqual(findController.getState().searchScope, [new Selection(1, 1, 2, 1)]);
586
587
findController.closeFindWidget();
588
589
editor.setSelections([new Selection(1, 1, 2, 1), new Selection(2, 1, 2, 5)]);
590
findController.start(findConfig);
591
assert.deepStrictEqual(findController.getState().searchScope, [new Selection(1, 1, 2, 1), new Selection(2, 1, 2, 5)]);
592
});
593
});
594
595
test('issue #58604: Do not update searchScope if it is empty', async () => {
596
await withAsyncTestCodeEditor([
597
'var x = (3 * 5)',
598
'var y = (3 * 5)',
599
'var z = (3 * 5)',
600
], { serviceCollection: serviceCollection, find: { autoFindInSelection: 'always', globalFindClipboard: false } }, async (editor) => {
601
// clipboardState = '';
602
editor.setSelection(new Range(1, 2, 1, 2));
603
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
604
605
await findController.start({
606
forceRevealReplace: false,
607
seedSearchStringFromSelection: 'none',
608
seedSearchStringFromNonEmptySelection: false,
609
seedSearchStringFromGlobalClipboard: false,
610
shouldFocus: FindStartFocusAction.NoFocusChange,
611
shouldAnimate: false,
612
updateSearchScope: true,
613
loop: true
614
});
615
616
assert.deepStrictEqual(findController.getState().searchScope, null);
617
});
618
});
619
620
test('issue #58604: Update searchScope if it is not empty', async () => {
621
await withAsyncTestCodeEditor([
622
'var x = (3 * 5)',
623
'var y = (3 * 5)',
624
'var z = (3 * 5)',
625
], { serviceCollection: serviceCollection, find: { autoFindInSelection: 'always', globalFindClipboard: false } }, async (editor) => {
626
// clipboardState = '';
627
editor.setSelection(new Range(1, 2, 1, 3));
628
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
629
630
await findController.start({
631
forceRevealReplace: false,
632
seedSearchStringFromSelection: 'none',
633
seedSearchStringFromNonEmptySelection: false,
634
seedSearchStringFromGlobalClipboard: false,
635
shouldFocus: FindStartFocusAction.NoFocusChange,
636
shouldAnimate: false,
637
updateSearchScope: true,
638
loop: true
639
});
640
641
assert.deepStrictEqual(findController.getState().searchScope, [new Selection(1, 2, 1, 3)]);
642
});
643
});
644
645
646
test('issue #27083: Find in selection when multiple lines are selected', async () => {
647
await withAsyncTestCodeEditor([
648
'var x = (3 * 5)',
649
'var y = (3 * 5)',
650
'var z = (3 * 5)',
651
], { serviceCollection: serviceCollection, find: { autoFindInSelection: 'multiline', globalFindClipboard: false } }, async (editor) => {
652
// clipboardState = '';
653
editor.setSelection(new Range(1, 6, 2, 1));
654
const findController = editor.registerAndInstantiateContribution(TestFindController.ID, TestFindController);
655
656
await findController.start({
657
forceRevealReplace: false,
658
seedSearchStringFromSelection: 'none',
659
seedSearchStringFromNonEmptySelection: false,
660
seedSearchStringFromGlobalClipboard: false,
661
shouldFocus: FindStartFocusAction.NoFocusChange,
662
shouldAnimate: false,
663
updateSearchScope: true,
664
loop: true
665
});
666
667
assert.deepStrictEqual(findController.getState().searchScope, [new Selection(1, 6, 2, 1)]);
668
});
669
});
670
});
671
672