Skip to content

Commit

Permalink
Fix microsoft#24887. Keybinding to toggle Find in selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Apr 28, 2017
1 parent d1384cf commit 669efe3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/vs/editor/contrib/find/common/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/find/common/findModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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',
Expand Down

0 comments on commit 669efe3

Please sign in to comment.