@@ -71,6 +71,16 @@ export interface IFindStartOptions {
71
71
loop : boolean ;
72
72
}
73
73
74
+ export interface IFindStartArguments {
75
+ searchString ?: string ;
76
+ replaceString ?: string ;
77
+ isRegex ?: boolean ;
78
+ matchWholeWord ?: boolean ;
79
+ isCaseSensitive ?: boolean ;
80
+ preserveCase ?: boolean ;
81
+ findInSelection ?: boolean ;
82
+ }
83
+
74
84
export class CommonFindController extends Disposable implements IEditorContribution {
75
85
76
86
public static readonly ID = 'editor.contrib.findController' ;
@@ -273,7 +283,7 @@ export class CommonFindController extends Disposable implements IEditorContribut
273
283
// overwritten in subclass
274
284
}
275
285
276
- protected async _start ( opts : IFindStartOptions ) : Promise < void > {
286
+ protected async _start ( opts : IFindStartOptions , newState ?: INewFindReplaceState ) : Promise < void > {
277
287
this . disposeModel ( ) ;
278
288
279
289
if ( ! this . _editor . hasModel ( ) ) {
@@ -282,6 +292,7 @@ export class CommonFindController extends Disposable implements IEditorContribut
282
292
}
283
293
284
294
let stateChanges : INewFindReplaceState = {
295
+ ...newState ,
285
296
isRevealed : true
286
297
} ;
287
298
@@ -315,7 +326,7 @@ export class CommonFindController extends Disposable implements IEditorContribut
315
326
}
316
327
317
328
// Overwrite isReplaceRevealed
318
- if ( opts . forceRevealReplace ) {
329
+ if ( opts . forceRevealReplace || stateChanges . isReplaceRevealed ) {
319
330
stateChanges . isReplaceRevealed = true ;
320
331
} else if ( ! this . _findWidgetVisible . get ( ) ) {
321
332
stateChanges . isReplaceRevealed = false ;
@@ -337,8 +348,8 @@ export class CommonFindController extends Disposable implements IEditorContribut
337
348
}
338
349
}
339
350
340
- public start ( opts : IFindStartOptions ) : Promise < void > {
341
- return this . _start ( opts ) ;
351
+ public start ( opts : IFindStartOptions , newState ?: INewFindReplaceState ) : Promise < void > {
352
+ return this . _start ( opts , newState ) ;
342
353
}
343
354
344
355
public moveToNextMatch ( ) : boolean {
@@ -423,7 +434,7 @@ export class FindController extends CommonFindController implements IFindControl
423
434
this . _findOptionsWidget = null ;
424
435
}
425
436
426
- protected override async _start ( opts : IFindStartOptions ) : Promise < void > {
437
+ protected override async _start ( opts : IFindStartOptions , newState ?: INewFindReplaceState ) : Promise < void > {
427
438
if ( ! this . _widget ) {
428
439
this . _createFindWidget ( ) ;
429
440
}
@@ -447,9 +458,9 @@ export class FindController extends CommonFindController implements IFindControl
447
458
break ;
448
459
}
449
460
450
- opts . updateSearchScope = updateSearchScope ;
461
+ opts . updateSearchScope = opts . updateSearchScope || updateSearchScope ;
451
462
452
- await super . _start ( opts ) ;
463
+ await super . _start ( opts , newState ) ;
453
464
454
465
if ( this . _widget ) {
455
466
if ( opts . shouldFocus === FindStartFocusAction . FocusReplaceInput ) {
@@ -520,6 +531,90 @@ StartFindAction.addImplementation(0, (accessor: ServicesAccessor, editor: ICodeE
520
531
} ) ;
521
532
} ) ;
522
533
534
+ const findArgDescription = {
535
+ description : 'Open a new In-Editor Find Widget.' ,
536
+ args : [ {
537
+ name : 'Open a new In-Editor Find Widget args' ,
538
+ schema : {
539
+ properties : {
540
+ searchString : { type : 'string' } ,
541
+ replaceString : { type : 'string' } ,
542
+ regex : { type : 'boolean' } ,
543
+ regexOverride : {
544
+ type : 'number' ,
545
+ description : nls . localize ( 'actions.find.isRegexOverride' , 'Overrides "Use Regular Expression" flag.\nThe flag will not be saved for the future.\n0: Do Nothing\n1: True\n2: False' )
546
+ } ,
547
+ wholeWord : { type : 'boolean' } ,
548
+ wholeWordOverride : {
549
+ type : 'number' ,
550
+ description : nls . localize ( 'actions.find.wholeWordOverride' , 'Overrides "Match Whole Word" flag.\nThe flag will not be saved for the future.\n0: Do Nothing\n1: True\n2: False' )
551
+ } ,
552
+ matchCase : { type : 'boolean' } ,
553
+ matchCaseOverride : {
554
+ type : 'number' ,
555
+ description : nls . localize ( 'actions.find.matchCaseOverride' , 'Overrides "Math Case" flag.\nThe flag will not be saved for the future.\n0: Do Nothing\n1: True\n2: False' )
556
+ } ,
557
+ preserveCase : { type : 'boolean' } ,
558
+ preserveCaseOverride : {
559
+ type : 'number' ,
560
+ description : nls . localize ( 'actions.find.preserveCaseOverride' , 'Overrides "Preserve Case" flag.\nThe flag will not be saved for the future.\n0: Do Nothing\n1: True\n2: False' )
561
+ } ,
562
+ findInSelection : { type : 'boolean' } ,
563
+ }
564
+ }
565
+ } ]
566
+ } as const ;
567
+
568
+ export class StartFindWithArgsAction extends EditorAction {
569
+
570
+ constructor ( ) {
571
+ super ( {
572
+ id : FIND_IDS . StartFindWithArgs ,
573
+ label : nls . localize ( 'startFindWithArgsAction' , "Find With Arguments" ) ,
574
+ alias : 'Find With Arguments' ,
575
+ precondition : undefined ,
576
+ kbOpts : {
577
+ kbExpr : null ,
578
+ primary : 0 ,
579
+ weight : KeybindingWeight . EditorContrib
580
+ } ,
581
+ description : findArgDescription
582
+ } ) ;
583
+ }
584
+
585
+ public async run ( accessor : ServicesAccessor | null , editor : ICodeEditor , args ?: IFindStartArguments ) : Promise < void > {
586
+ let controller = CommonFindController . get ( editor ) ;
587
+ if ( controller ) {
588
+ const newState : INewFindReplaceState = args ? {
589
+ searchString : args . searchString ,
590
+ replaceString : args . replaceString ,
591
+ isReplaceRevealed : args . replaceString !== undefined ,
592
+ isRegex : args . isRegex ,
593
+ // isRegexOverride: args.regexOverride,
594
+ wholeWord : args . matchWholeWord ,
595
+ // wholeWordOverride: args.wholeWordOverride,
596
+ matchCase : args . isCaseSensitive ,
597
+ // matchCaseOverride: args.matchCaseOverride,
598
+ preserveCase : args . preserveCase ,
599
+ // preserveCaseOverride: args.preserveCaseOverride,
600
+ } : { } ;
601
+
602
+ await controller . start ( {
603
+ forceRevealReplace : false ,
604
+ seedSearchStringFromSelection : ( controller . getState ( ) . searchString . length === 0 ) && editor . getOption ( EditorOption . find ) . seedSearchStringFromSelection !== 'never' ? 'single' : 'none' ,
605
+ seedSearchStringFromNonEmptySelection : editor . getOption ( EditorOption . find ) . seedSearchStringFromSelection === 'selection' ,
606
+ seedSearchStringFromGlobalClipboard : true ,
607
+ shouldFocus : FindStartFocusAction . FocusFindInput ,
608
+ shouldAnimate : true ,
609
+ updateSearchScope : args ?. findInSelection || false ,
610
+ loop : editor . getOption ( EditorOption . find ) . loop
611
+ } , newState ) ;
612
+
613
+ controller . setGlobalBufferTerm ( controller . getState ( ) . searchString ) ;
614
+ }
615
+ }
616
+ }
617
+
523
618
export class StartFindWithSelectionAction extends EditorAction {
524
619
525
620
constructor ( ) {
@@ -772,6 +867,7 @@ StartFindReplaceAction.addImplementation(0, (accessor: ServicesAccessor, editor:
772
867
773
868
registerEditorContribution ( CommonFindController . ID , FindController ) ;
774
869
870
+ registerEditorAction ( StartFindWithArgsAction ) ;
775
871
registerEditorAction ( StartFindWithSelectionAction ) ;
776
872
registerEditorAction ( NextMatchFindAction ) ;
777
873
registerEditorAction ( PreviousMatchFindAction ) ;
0 commit comments