Merge pull request #107597 from turara/resolve-107208
Add keybinding shortcut for "Preserve case" replace option
This commit is contained in:
commit
c7c471bdde
10 changed files with 53 additions and 5 deletions
|
@ -28,6 +28,7 @@ export interface IReplaceInputOptions extends IReplaceInputStyles {
|
||||||
readonly flexibleWidth?: boolean;
|
readonly flexibleWidth?: boolean;
|
||||||
readonly flexibleMaxHeight?: number;
|
readonly flexibleMaxHeight?: number;
|
||||||
|
|
||||||
|
readonly appendPreserveCaseLabel?: string;
|
||||||
readonly history?: string[];
|
readonly history?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +129,7 @@ export class ReplaceInput extends Widget {
|
||||||
this.inputValidationErrorBackground = options.inputValidationErrorBackground;
|
this.inputValidationErrorBackground = options.inputValidationErrorBackground;
|
||||||
this.inputValidationErrorForeground = options.inputValidationErrorForeground;
|
this.inputValidationErrorForeground = options.inputValidationErrorForeground;
|
||||||
|
|
||||||
|
const appendPreserveCaseLabel = options.appendPreserveCaseLabel || '';
|
||||||
const history = options.history || [];
|
const history = options.history || [];
|
||||||
const flexibleHeight = !!options.flexibleHeight;
|
const flexibleHeight = !!options.flexibleHeight;
|
||||||
const flexibleWidth = !!options.flexibleWidth;
|
const flexibleWidth = !!options.flexibleWidth;
|
||||||
|
@ -161,7 +163,7 @@ export class ReplaceInput extends Widget {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.preserveCase = this._register(new PreserveCaseCheckbox({
|
this.preserveCase = this._register(new PreserveCaseCheckbox({
|
||||||
appendTitle: '',
|
appendTitle: appendPreserveCaseLabel,
|
||||||
isChecked: false,
|
isChecked: false,
|
||||||
inputActiveOptionBorder: this.inputActiveOptionBorder,
|
inputActiveOptionBorder: this.inputActiveOptionBorder,
|
||||||
inputActiveOptionForeground: this.inputActiveOptionForeground,
|
inputActiveOptionForeground: this.inputActiveOptionForeground,
|
||||||
|
|
|
@ -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 { EditorAction, EditorCommand, ServicesAccessor, registerEditorAction, registerEditorCommand, registerEditorContribution, MultiEditorAction, registerMultiEditorAction } from 'vs/editor/browser/editorExtensions';
|
||||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
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 { FindOptionsWidget } from 'vs/editor/contrib/find/findOptionsWidget';
|
||||||
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
|
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
|
||||||
import { FindWidget, IFindController } from 'vs/editor/contrib/find/findWidget';
|
import { FindWidget, IFindController } from 'vs/editor/contrib/find/findWidget';
|
||||||
|
@ -224,7 +224,9 @@ export class CommonFindController extends Disposable implements IEditorContribut
|
||||||
|
|
||||||
public togglePreserveCase(): void {
|
public togglePreserveCase(): void {
|
||||||
this._state.change({ preserveCase: !this._state.preserveCase }, false);
|
this._state.change({ preserveCase: !this._state.preserveCase }, false);
|
||||||
this.highlightFindOptions();
|
if (!this._state.isRevealed) {
|
||||||
|
this.highlightFindOptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public toggleSearchScope(): void {
|
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({
|
registerEditorCommand(new FindCommand({
|
||||||
id: FIND_IDS.ReplaceOneAction,
|
id: FIND_IDS.ReplaceOneAction,
|
||||||
precondition: CONTEXT_FIND_WIDGET_VISIBLE,
|
precondition: CONTEXT_FIND_WIDGET_VISIBLE,
|
||||||
|
|
|
@ -47,6 +47,10 @@ export const ToggleSearchScopeKeybinding: IKeybindings = {
|
||||||
primary: KeyMod.Alt | KeyCode.KEY_L,
|
primary: KeyMod.Alt | KeyCode.KEY_L,
|
||||||
mac: { primary: KeyMod.CtrlCmd | 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 = {
|
export const FIND_IDS = {
|
||||||
StartFindAction: 'actions.find',
|
StartFindAction: 'actions.find',
|
||||||
|
|
|
@ -353,6 +353,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
|
||||||
if (e.matchCase) {
|
if (e.matchCase) {
|
||||||
this._findInput.setCaseSensitive(this._state.matchCase);
|
this._findInput.setCaseSensitive(this._state.matchCase);
|
||||||
}
|
}
|
||||||
|
if (e.preserveCase) {
|
||||||
|
this._replaceInput.setPreserveCase(this._state.preserveCase);
|
||||||
|
}
|
||||||
if (e.searchScope) {
|
if (e.searchScope) {
|
||||||
if (this._state.searchScope) {
|
if (this._state.searchScope) {
|
||||||
this._toggleSelectionFind.checked = true;
|
this._toggleSelectionFind.checked = true;
|
||||||
|
@ -1087,6 +1090,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
|
||||||
this._replaceInput = this._register(new ContextScopedReplaceInput(null, undefined, {
|
this._replaceInput = this._register(new ContextScopedReplaceInput(null, undefined, {
|
||||||
label: NLS_REPLACE_INPUT_LABEL,
|
label: NLS_REPLACE_INPUT_LABEL,
|
||||||
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
|
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
|
||||||
|
appendPreserveCaseLabel: this._keybindingLabelFor(FIND_IDS.TogglePreserveCaseCommand),
|
||||||
history: [],
|
history: [],
|
||||||
flexibleHeight,
|
flexibleHeight,
|
||||||
flexibleWidth,
|
flexibleWidth,
|
||||||
|
|
|
@ -140,6 +140,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
|
||||||
this._findInput.setRegex(this._state.isRegex);
|
this._findInput.setRegex(this._state.isRegex);
|
||||||
this._findInput.setWholeWords(this._state.wholeWord);
|
this._findInput.setWholeWords(this._state.wholeWord);
|
||||||
this._findInput.setCaseSensitive(this._state.matchCase);
|
this._findInput.setCaseSensitive(this._state.matchCase);
|
||||||
|
this._replaceInput.setPreserveCase(this._state.preserveCase);
|
||||||
this.findFirst();
|
this.findFirst();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||||
import * as platform from 'vs/base/common/platform';
|
import * as platform from 'vs/base/common/platform';
|
||||||
import { dirname } from 'vs/base/common/resources';
|
import { dirname } from 'vs/base/common/resources';
|
||||||
import { URI } from 'vs/base/common/uri';
|
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 * as nls from 'vs/nls';
|
||||||
import { ICommandAction, MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
import { ICommandAction, MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
||||||
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
|
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 { 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 { 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 { 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 { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
|
||||||
import { registerContributions as searchWidgetContributions } from 'vs/workbench/contrib/search/browser/searchWidget';
|
import { registerContributions as searchWidgetContributions } from 'vs/workbench/contrib/search/browser/searchWidget';
|
||||||
import * as Constants from 'vs/workbench/contrib/search/common/constants';
|
import * as Constants from 'vs/workbench/contrib/search/common/constants';
|
||||||
|
@ -642,6 +642,13 @@ KeybindingsRegistry.registerCommandAndKeybindingRule(Object.assign({
|
||||||
handler: toggleRegexCommand
|
handler: toggleRegexCommand
|
||||||
}, ToggleRegexKeybinding));
|
}, ToggleRegexKeybinding));
|
||||||
|
|
||||||
|
KeybindingsRegistry.registerCommandAndKeybindingRule(Object.assign({
|
||||||
|
id: Constants.TogglePreserveCaseId,
|
||||||
|
weight: KeybindingWeight.WorkbenchContrib,
|
||||||
|
when: Constants.SearchViewFocusedKey,
|
||||||
|
handler: togglePreserveCaseCommand
|
||||||
|
}, TogglePreserveCaseKeybinding));
|
||||||
|
|
||||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||||
id: Constants.AddCursorsAtSearchResults,
|
id: Constants.AddCursorsAtSearchResults,
|
||||||
weight: KeybindingWeight.WorkbenchContrib,
|
weight: KeybindingWeight.WorkbenchContrib,
|
||||||
|
|
|
@ -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 {
|
export class FocusNextInputAction extends Action {
|
||||||
|
|
||||||
static readonly ID = 'search.focus.nextInputBox';
|
static readonly ID = 'search.focus.nextInputBox';
|
||||||
|
|
|
@ -1160,6 +1160,11 @@ export class SearchView extends ViewPane {
|
||||||
this.triggerQueryChange();
|
this.triggerQueryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
togglePreserveCase(): void {
|
||||||
|
this.searchWidget.replaceInput.setPreserveCase(!this.searchWidget.replaceInput.getPreserveCase());
|
||||||
|
this.triggerQueryChange();
|
||||||
|
}
|
||||||
|
|
||||||
setSearchParameters(args: IFindInFilesArgs = {}): void {
|
setSearchParameters(args: IFindInFilesArgs = {}): void {
|
||||||
if (typeof args.isCaseSensitive === 'boolean') {
|
if (typeof args.isCaseSensitive === 'boolean') {
|
||||||
this.searchWidget.searchInput.setCaseSensitive(args.isCaseSensitive);
|
this.searchWidget.searchInput.setCaseSensitive(args.isCaseSensitive);
|
||||||
|
|
|
@ -393,6 +393,7 @@ export class SearchWidget extends Widget {
|
||||||
this.replaceInput = this._register(new ContextScopedReplaceInput(replaceBox, this.contextViewService, {
|
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'),
|
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"),
|
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
|
||||||
|
appendPreserveCaseLabel: appendKeyBindingLabel('', this.keyBindingService.lookupKeybinding(Constants.TogglePreserveCaseId), this.keyBindingService),
|
||||||
history: options.replaceHistory,
|
history: options.replaceHistory,
|
||||||
flexibleHeight: true,
|
flexibleHeight: true,
|
||||||
flexibleMaxHeight: SearchWidget.INPUT_MAX_HEIGHT
|
flexibleMaxHeight: SearchWidget.INPUT_MAX_HEIGHT
|
||||||
|
|
|
@ -26,6 +26,7 @@ export const CloseReplaceWidgetActionId = 'closeReplaceInFilesWidget';
|
||||||
export const ToggleCaseSensitiveCommandId = 'toggleSearchCaseSensitive';
|
export const ToggleCaseSensitiveCommandId = 'toggleSearchCaseSensitive';
|
||||||
export const ToggleWholeWordCommandId = 'toggleSearchWholeWord';
|
export const ToggleWholeWordCommandId = 'toggleSearchWholeWord';
|
||||||
export const ToggleRegexCommandId = 'toggleSearchRegex';
|
export const ToggleRegexCommandId = 'toggleSearchRegex';
|
||||||
|
export const TogglePreserveCaseId = 'toggleSearchPreserveCase';
|
||||||
export const AddCursorsAtSearchResults = 'addCursorsAtSearchResults';
|
export const AddCursorsAtSearchResults = 'addCursorsAtSearchResults';
|
||||||
export const RevealInSideBarForSearchResults = 'search.action.revealInSideBar';
|
export const RevealInSideBarForSearchResults = 'search.action.revealInSideBar';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue