Skip to content

Commit 59c9a3e

Browse files
committed
Fix microsoft#17562. Focus the InputBox if it is empty when users do replace
1 parent 6f790f7 commit 59c9a3e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/vs/editor/contrib/find/common/findController.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,21 @@ export class StartFindReplaceAction extends EditorAction {
506506
}
507507

508508
let controller = CommonFindController.get(editor);
509+
let currentSelection = editor.getSelection();
510+
// we only seed search string from selection when the current selection is single line and not empty.
511+
let seedSearchStringFromSelection = currentSelection.isEmpty() ||
512+
currentSelection.startLineNumber !== currentSelection.endLineNumber;
513+
let oldSearchString = controller.getState().searchString;
514+
// if the existing search string in find widget is empty and we don't seed search string from selection, it means the Find Input
515+
// is still empty, so we should focus the Find Input instead of Replace Input.
516+
let shouldFocus = !oldSearchString && seedSearchStringFromSelection ?
517+
FindStartFocusAction.FocusFindInput : FindStartFocusAction.FocusReplaceInput;
518+
509519
if (controller) {
510520
controller.start({
511521
forceRevealReplace: true,
512-
seedSearchStringFromSelection: true,
513-
shouldFocus: FindStartFocusAction.FocusReplaceInput,
522+
seedSearchStringFromSelection: seedSearchStringFromSelection,
523+
shouldFocus: shouldFocus,
514524
shouldAnimate: true
515525
});
516526
}

0 commit comments

Comments
 (0)