Merge pull request #107597 from turara/resolve-107208

Add keybinding shortcut for "Preserve case" replace option
This commit is contained in:
Rob Lourens 2020-10-05 17:20:12 -07:00 committed by GitHub
commit c7c471bdde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 5 deletions

View file

@ -28,6 +28,7 @@ export interface IReplaceInputOptions extends IReplaceInputStyles {
readonly flexibleWidth?: boolean;
readonly flexibleMaxHeight?: number;
readonly appendPreserveCaseLabel?: string;
readonly history?: string[];
}
@ -128,6 +129,7 @@ export class ReplaceInput extends Widget {
this.inputValidationErrorBackground = options.inputValidationErrorBackground;
this.inputValidationErrorForeground = options.inputValidationErrorForeground;
const appendPreserveCaseLabel = options.appendPreserveCaseLabel || '';
const history = options.history || [];
const flexibleHeight = !!options.flexibleHeight;
const flexibleWidth = !!options.flexibleWidth;
@ -161,7 +163,7 @@ export class ReplaceInput extends Widget {
}));
this.preserveCase = this._register(new PreserveCaseCheckbox({
appendTitle: '',
appendTitle: appendPreserveCaseLabel,
isChecked: false,
inputActiveOptionBorder: this.inputActiveOptionBorder,
inputActiveOptionForeground: this.inputActiveOptionForeground,

View file

@ -12,7 +12,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, EditorCommand, ServicesAccessor, registerEditorAction, registerEditorCommand, registerEditorContribution, MultiEditorAction, registerMultiEditorAction } from 'vs/editor/browser/editorExtensions';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_FIND_WIDGET_VISIBLE, FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleSearchScopeKeybinding, ToggleWholeWordKeybinding, CONTEXT_REPLACE_INPUT_FOCUSED } from 'vs/editor/contrib/find/findModel';
import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_FIND_WIDGET_VISIBLE, FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, TogglePreserveCaseKeybinding, ToggleRegexKeybinding, ToggleSearchScopeKeybinding, ToggleWholeWordKeybinding, CONTEXT_REPLACE_INPUT_FOCUSED } from 'vs/editor/contrib/find/findModel';
import { FindOptionsWidget } from 'vs/editor/contrib/find/findOptionsWidget';
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
import { FindWidget, IFindController } from 'vs/editor/contrib/find/findWidget';
@ -224,7 +224,9 @@ export class CommonFindController extends Disposable implements IEditorContribut
public togglePreserveCase(): void {
this._state.change({ preserveCase: !this._state.preserveCase }, false);
this.highlightFindOptions();
if (!this._state.isRevealed) {
this.highlightFindOptions();
}
}
public toggleSearchScope(): void {
@ -858,6 +860,20 @@ registerEditorCommand(new FindCommand({
}
}));
registerEditorCommand(new FindCommand({
id: FIND_IDS.TogglePreserveCaseCommand,
precondition: undefined,
handler: x => x.togglePreserveCase(),
kbOpts: {
weight: KeybindingWeight.EditorContrib + 5,
kbExpr: EditorContextKeys.focus,
primary: TogglePreserveCaseKeybinding.primary,
mac: TogglePreserveCaseKeybinding.mac,
win: TogglePreserveCaseKeybinding.win,
linux: TogglePreserveCaseKeybinding.linux
}
}));
registerEditorCommand(new FindCommand({
id: FIND_IDS.ReplaceOneAction,
precondition: CONTEXT_FIND_WIDGET_VISIBLE,

View file

@ -47,6 +47,10 @@ export const ToggleSearchScopeKeybinding: IKeybindings = {
primary: KeyMod.Alt | KeyCode.KEY_L,
mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_L }
};
export const TogglePreserveCaseKeybinding: IKeybindings = {
primary: KeyMod.Alt | KeyCode.KEY_P,
mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_P }
};
export const FIND_IDS = {
StartFindAction: 'actions.find',

View file

@ -353,6 +353,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
if (e.matchCase) {
this._findInput.setCaseSensitive(this._state.matchCase);
}
if (e.preserveCase) {
this._replaceInput.setPreserveCase(this._state.preserveCase);
}
if (e.searchScope) {
if (this._state.searchScope) {
this._toggleSelectionFind.checked = true;
@ -1087,6 +1090,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
this._replaceInput = this._register(new ContextScopedReplaceInput(null, undefined, {
label: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
appendPreserveCaseLabel: this._keybindingLabelFor(FIND_IDS.TogglePreserveCaseCommand),
history: [],
flexibleHeight,
flexibleWidth,

View file

@ -140,6 +140,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
this._findInput.setRegex(this._state.isRegex);
this._findInput.setWholeWords(this._state.wholeWord);
this._findInput.setCaseSensitive(this._state.matchCase);
this._replaceInput.setPreserveCase(this._state.preserveCase);
this.findFirst();
}));

View file

@ -10,7 +10,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import { dirname } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
import { ToggleCaseSensitiveKeybinding, TogglePreserveCaseKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
import * as nls from 'vs/nls';
import { ICommandAction, MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
@ -31,7 +31,7 @@ import { Extensions as ViewExtensions, IViewsRegistry, IViewContainersRegistry,
import { getMultiSelectedResources } from 'vs/workbench/contrib/files/browser/files';
import { ExplorerFolderContext, ExplorerRootContext, FilesExplorerFocusCondition, IExplorerService, VIEWLET_ID as VIEWLET_ID_FILES } from 'vs/workbench/contrib/files/common/files';
import { registerContributions as replaceContributions } from 'vs/workbench/contrib/search/browser/replaceContributions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, toggleRegexCommand, toggleWholeWordCommand, FindInFilesCommand, ToggleSearchOnTypeAction, ExpandAllAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, togglePreserveCaseCommand, toggleRegexCommand, toggleWholeWordCommand, FindInFilesCommand, ToggleSearchOnTypeAction, ExpandAllAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
import { registerContributions as searchWidgetContributions } from 'vs/workbench/contrib/search/browser/searchWidget';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
@ -642,6 +642,13 @@ KeybindingsRegistry.registerCommandAndKeybindingRule(Object.assign({
handler: toggleRegexCommand
}, ToggleRegexKeybinding));
KeybindingsRegistry.registerCommandAndKeybindingRule(Object.assign({
id: Constants.TogglePreserveCaseId,
weight: KeybindingWeight.WorkbenchContrib,
when: Constants.SearchViewFocusedKey,
handler: togglePreserveCaseCommand
}, TogglePreserveCaseKeybinding));
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.AddCursorsAtSearchResults,
weight: KeybindingWeight.WorkbenchContrib,

View file

@ -82,6 +82,13 @@ export const toggleRegexCommand = (accessor: ServicesAccessor) => {
}
};
export const togglePreserveCaseCommand = (accessor: ServicesAccessor) => {
const searchView = getSearchView(accessor.get(IViewsService));
if (searchView) {
searchView.togglePreserveCase();
}
};
export class FocusNextInputAction extends Action {
static readonly ID = 'search.focus.nextInputBox';

View file

@ -1160,6 +1160,11 @@ export class SearchView extends ViewPane {
this.triggerQueryChange();
}
togglePreserveCase(): void {
this.searchWidget.replaceInput.setPreserveCase(!this.searchWidget.replaceInput.getPreserveCase());
this.triggerQueryChange();
}
setSearchParameters(args: IFindInFilesArgs = {}): void {
if (typeof args.isCaseSensitive === 'boolean') {
this.searchWidget.searchInput.setCaseSensitive(args.isCaseSensitive);

View file

@ -393,6 +393,7 @@ export class SearchWidget extends Widget {
this.replaceInput = this._register(new ContextScopedReplaceInput(replaceBox, this.contextViewService, {
label: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview or Escape to cancel'),
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
appendPreserveCaseLabel: appendKeyBindingLabel('', this.keyBindingService.lookupKeybinding(Constants.TogglePreserveCaseId), this.keyBindingService),
history: options.replaceHistory,
flexibleHeight: true,
flexibleMaxHeight: SearchWidget.INPUT_MAX_HEIGHT

View file

@ -26,6 +26,7 @@ export const CloseReplaceWidgetActionId = 'closeReplaceInFilesWidget';
export const ToggleCaseSensitiveCommandId = 'toggleSearchCaseSensitive';
export const ToggleWholeWordCommandId = 'toggleSearchWholeWord';
export const ToggleRegexCommandId = 'toggleSearchRegex';
export const TogglePreserveCaseId = 'toggleSearchPreserveCase';
export const AddCursorsAtSearchResults = 'addCursorsAtSearchResults';
export const RevealInSideBarForSearchResults = 'search.action.revealInSideBar';