diff --git a/src/vs/editor/contrib/find/common/findController.ts b/src/vs/editor/contrib/find/common/findController.ts index e3a133ee56089..c788dafd5f26b 100644 --- a/src/vs/editor/contrib/find/common/findController.ts +++ b/src/vs/editor/contrib/find/common/findController.ts @@ -14,7 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection'; import * as strings from 'vs/base/common/strings'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { editorAction, commonEditorContribution, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; -import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/common/findModel'; +import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ToggleSearchScopeKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/common/findModel'; import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/common/findState'; import { DocumentHighlightProviderRegistry } from 'vs/editor/common/modes'; import { RunOnceScheduler, Delayer } from 'vs/base/common/async'; @@ -153,6 +153,20 @@ export class CommonFindController extends Disposable implements editorCommon.IEd this._state.change({ isRegex: !this._state.isRegex }, false); } + public toggleSearchScope(): void { + if (this._state.searchScope) { + this._state.change({ searchScope: null }, true); + } else { + let selection = this._editor.getSelection(); + if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) { + selection = selection.setEndPosition(selection.endLineNumber - 1, 1); + } + if (!selection.isEmpty()) { + this._state.change({ searchScope: selection }, true); + } + } + } + public setSearchString(searchString: string): void { this._state.change({ searchString: searchString }, false); } @@ -1064,6 +1078,20 @@ CommonEditorRegistry.registerEditorCommand(new FindCommand({ } })); +CommonEditorRegistry.registerEditorCommand(new FindCommand({ + id: FIND_IDS.ToggleSearchScopeCommand, + precondition: null, + handler: x => x.toggleSearchScope(), + kbOpts: { + weight: CommonEditorRegistry.commandWeight(5), + kbExpr: EditorContextKeys.focus, + primary: ToggleSearchScopeKeybinding.primary, + mac: ToggleSearchScopeKeybinding.mac, + win: ToggleSearchScopeKeybinding.win, + linux: ToggleSearchScopeKeybinding.linux + } +})); + CommonEditorRegistry.registerEditorCommand(new FindCommand({ id: FIND_IDS.ReplaceOneAction, precondition: CONTEXT_FIND_WIDGET_VISIBLE, diff --git a/src/vs/editor/contrib/find/common/findModel.ts b/src/vs/editor/contrib/find/common/findModel.ts index a21568981d2b8..9667c467e1fbb 100644 --- a/src/vs/editor/contrib/find/common/findModel.ts +++ b/src/vs/editor/contrib/find/common/findModel.ts @@ -33,6 +33,9 @@ export const ToggleRegexKeybinding: IKeybindings = { primary: KeyMod.Alt | KeyCode.KEY_R, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_R } }; +export const ToggleSearchScopeKeybinding: IKeybindings = { + primary: KeyMod.Alt | KeyCode.KEY_S +}; export const ShowPreviousFindTermKeybinding: IKeybindings = { primary: KeyMod.Alt | KeyCode.UpArrow }; @@ -55,6 +58,7 @@ export const FIND_IDS = { ToggleCaseSensitiveCommand: 'toggleFindCaseSensitive', ToggleWholeWordCommand: 'toggleFindWholeWord', ToggleRegexCommand: 'toggleFindRegex', + ToggleSearchScopeCommand: 'toggleSearchScope', ReplaceOneAction: 'editor.action.replaceOne', ReplaceAllAction: 'editor.action.replaceAll', SelectAllMatchesAction: 'editor.action.selectAllMatches',