Skip to content

Commit 669efe3

Browse files
committed
Fix microsoft#24887. Keybinding to toggle Find in selection.
1 parent d1384cf commit 669efe3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection';
1414
import * as strings from 'vs/base/common/strings';
1515
import * as editorCommon from 'vs/editor/common/editorCommon';
1616
import { editorAction, commonEditorContribution, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
17-
import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/common/findModel';
17+
import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ToggleSearchScopeKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/common/findModel';
1818
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/common/findState';
1919
import { DocumentHighlightProviderRegistry } from 'vs/editor/common/modes';
2020
import { RunOnceScheduler, Delayer } from 'vs/base/common/async';
@@ -153,6 +153,20 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
153153
this._state.change({ isRegex: !this._state.isRegex }, false);
154154
}
155155

156+
public toggleSearchScope(): void {
157+
if (this._state.searchScope) {
158+
this._state.change({ searchScope: null }, true);
159+
} else {
160+
let selection = this._editor.getSelection();
161+
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
162+
selection = selection.setEndPosition(selection.endLineNumber - 1, 1);
163+
}
164+
if (!selection.isEmpty()) {
165+
this._state.change({ searchScope: selection }, true);
166+
}
167+
}
168+
}
169+
156170
public setSearchString(searchString: string): void {
157171
this._state.change({ searchString: searchString }, false);
158172
}
@@ -1064,6 +1078,20 @@ CommonEditorRegistry.registerEditorCommand(new FindCommand({
10641078
}
10651079
}));
10661080

1081+
CommonEditorRegistry.registerEditorCommand(new FindCommand({
1082+
id: FIND_IDS.ToggleSearchScopeCommand,
1083+
precondition: null,
1084+
handler: x => x.toggleSearchScope(),
1085+
kbOpts: {
1086+
weight: CommonEditorRegistry.commandWeight(5),
1087+
kbExpr: EditorContextKeys.focus,
1088+
primary: ToggleSearchScopeKeybinding.primary,
1089+
mac: ToggleSearchScopeKeybinding.mac,
1090+
win: ToggleSearchScopeKeybinding.win,
1091+
linux: ToggleSearchScopeKeybinding.linux
1092+
}
1093+
}));
1094+
10671095
CommonEditorRegistry.registerEditorCommand(new FindCommand({
10681096
id: FIND_IDS.ReplaceOneAction,
10691097
precondition: CONTEXT_FIND_WIDGET_VISIBLE,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const ToggleRegexKeybinding: IKeybindings = {
3333
primary: KeyMod.Alt | KeyCode.KEY_R,
3434
mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_R }
3535
};
36+
export const ToggleSearchScopeKeybinding: IKeybindings = {
37+
primary: KeyMod.Alt | KeyCode.KEY_S
38+
};
3639
export const ShowPreviousFindTermKeybinding: IKeybindings = {
3740
primary: KeyMod.Alt | KeyCode.UpArrow
3841
};
@@ -55,6 +58,7 @@ export const FIND_IDS = {
5558
ToggleCaseSensitiveCommand: 'toggleFindCaseSensitive',
5659
ToggleWholeWordCommand: 'toggleFindWholeWord',
5760
ToggleRegexCommand: 'toggleFindRegex',
61+
ToggleSearchScopeCommand: 'toggleSearchScope',
5862
ReplaceOneAction: 'editor.action.replaceOne',
5963
ReplaceAllAction: 'editor.action.replaceAll',
6064
SelectAllMatchesAction: 'editor.action.selectAllMatches',

0 commit comments

Comments
 (0)