Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #36596. Cmd+e should always populate the search string #38908

Merged
merged 1 commit into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/vs/editor/contrib/find/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
if (shouldRestartFind) {
this._start({
forceRevealReplace: false,
seedSearchStringFromSelection: false,
seedSearchStringFromSelection: false && this._editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: false,
});
Expand Down Expand Up @@ -233,8 +233,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
isRevealed: true
};

// Consider editor selection and overwrite the state with it
if (opts.seedSearchStringFromSelection && this._editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection) {
if (opts.seedSearchStringFromSelection) {
let selectionSearchString = getSelectionSearchString(this._editor);
if (selectionSearchString) {
if (this._state.isRegex) {
Expand Down Expand Up @@ -379,10 +378,37 @@ export class StartFindAction extends EditorAction {
precondition: null,
kbOpts: {
kbExpr: null,
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
}
});
}

public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
let controller = CommonFindController.get(editor);
if (controller) {
controller.start({
forceRevealReplace: false,
seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
shouldFocus: FindStartFocusAction.FocusFindInput,
shouldAnimate: true
});
}
}
}

export class StartFindWithSelectionAction extends EditorAction {

constructor() {
super({
id: FIND_IDS.StartFindWithSelection,
label: nls.localize('startFindAction', "Find"),
alias: 'Find',
precondition: null,
kbOpts: {
kbExpr: null,
primary: null,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
secondary: [KeyMod.CtrlCmd | KeyCode.KEY_E]
primary: KeyMod.CtrlCmd | KeyCode.KEY_E,
}
}
});
Expand All @@ -400,14 +426,13 @@ export class StartFindAction extends EditorAction {
}
}
}

export abstract class MatchFindAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
let controller = CommonFindController.get(editor);
if (controller && !this._run(controller)) {
controller.start({
forceRevealReplace: false,
seedSearchStringFromSelection: (controller.getState().searchString.length === 0),
seedSearchStringFromSelection: (controller.getState().searchString.length === 0) && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: true
});
Expand Down Expand Up @@ -549,7 +574,7 @@ export class StartFindReplaceAction extends EditorAction {
let currentSelection = editor.getSelection();
// we only seed search string from selection when the current selection is single line and not empty.
let seedSearchStringFromSelection = !currentSelection.isEmpty() &&
currentSelection.startLineNumber === currentSelection.endLineNumber;
currentSelection.startLineNumber === currentSelection.endLineNumber && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection;
let oldSearchString = controller.getState().searchString;
// if the existing search string in find widget is empty and we don't seed search string from selection, it means the Find Input
// is still empty, so we should focus the Find Input instead of Replace Input.
Expand Down Expand Up @@ -618,6 +643,7 @@ export class ShowPreviousFindTermAction extends MatchFindAction {
registerEditorContribution(FindController);

registerEditorAction(StartFindAction);
registerEditorAction(StartFindWithSelectionAction);
registerEditorAction(NextMatchFindAction);
registerEditorAction(PreviousMatchFindAction);
registerEditorAction(NextSelectionMatchFindAction);
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/contrib/find/findModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const ShowNextFindTermKeybinding: IKeybindings = {

export const FIND_IDS = {
StartFindAction: 'actions.find',
StartFindWithSelection: 'actions.findWithSelection',
NextMatchFindAction: 'editor.action.nextMatchFindAction',
PreviousMatchFindAction: 'editor.action.previousMatchFindAction',
NextSelectionMatchFindAction: 'editor.action.nextSelectionMatchFindAction',
Expand Down