Skip to content

Commit beffdb6

Browse files
committed
Also use ctrl+enter for multiline search
Fix microsoft#80361
1 parent b035116 commit beffdb6

3 files changed

Lines changed: 32 additions & 26 deletions

File tree

src/vs/base/browser/ui/inputbox/inputBox.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,19 @@ export class InputBox extends Widget {
581581
}
582582
}
583583

584+
public insertAtCursor(text: string): void {
585+
const inputElement = this.inputElement;
586+
const start = inputElement.selectionStart;
587+
const end = inputElement.selectionEnd;
588+
const content = inputElement.value;
589+
590+
if (start !== null && end !== null) {
591+
this.value = content.substr(0, start) + text + content.substr(end);
592+
inputElement.setSelectionRange(start + 1, start + 1);
593+
this.layout();
594+
}
595+
}
596+
584597
public dispose(): void {
585598
this._hideMessage();
586599

src/vs/editor/contrib/find/findWidget.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -778,19 +778,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
778778

779779
private _onFindInputKeyDown(e: IKeyboardEvent): void {
780780
if (e.equals(ctrlKeyMod | KeyCode.Enter)) {
781-
const inputElement = this._findInput.inputBox.inputElement;
782-
const start = inputElement.selectionStart;
783-
const end = inputElement.selectionEnd;
784-
const content = inputElement.value;
785-
786-
if (start !== null && end !== null) {
787-
const value = content.substr(0, start) + '\n' + content.substr(end);
788-
this._findInput.inputBox.value = value;
789-
inputElement.setSelectionRange(start + 1, start + 1);
790-
this._findInput.inputBox.layout();
791-
e.preventDefault();
792-
return;
793-
}
781+
this._findInput.inputBox.insertAtCursor('\n');
782+
e.preventDefault();
783+
return;
794784
}
795785

796786
if (e.equals(KeyCode.Tab)) {
@@ -832,19 +822,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
832822

833823
}
834824

835-
const inputElement = this._replaceInput.inputBox.inputElement;
836-
const start = inputElement.selectionStart;
837-
const end = inputElement.selectionEnd;
838-
const content = inputElement.value;
839-
840-
if (start !== null && end !== null) {
841-
const value = content.substr(0, start) + '\n' + content.substr(end);
842-
this._replaceInput.inputBox.value = value;
843-
inputElement.setSelectionRange(start + 1, start + 1);
844-
this._replaceInput.inputBox.layout();
845-
e.preventDefault();
846-
return;
847-
}
825+
this._replaceInput.inputBox.insertAtCursor('\n');
826+
e.preventDefault();
827+
return;
848828
}
849829

850830
if (e.equals(KeyCode.Tab)) {

src/vs/workbench/contrib/search/browser/searchWidget.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
3434
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
3535
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
3636
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
37+
import { isMacintosh } from 'vs/base/common/platform';
3738

3839
export interface ISearchWidgetOptions {
3940
value?: string;
@@ -76,6 +77,8 @@ class ReplaceAllAction extends Action {
7677
}
7778
}
7879

80+
const ctrlKeyMod = (isMacintosh ? KeyMod.WinCtrl : KeyMod.CtrlCmd);
81+
7982
export class SearchWidget extends Widget {
8083

8184
private static readonly REPLACE_ALL_DISABLED_LABEL = nls.localize('search.action.replaceAll.disabled.label', "Replace All (Submit Search to Enable)");
@@ -446,6 +449,11 @@ export class SearchWidget extends Widget {
446449
}
447450

448451
private onSearchInputKeyDown(keyboardEvent: IKeyboardEvent) {
452+
if (keyboardEvent.equals(ctrlKeyMod | KeyCode.Enter)) {
453+
this.searchInput.inputBox.insertAtCursor('\n');
454+
keyboardEvent.preventDefault();
455+
}
456+
449457
if (keyboardEvent.equals(KeyCode.Enter)) {
450458
this.submitSearch();
451459
keyboardEvent.preventDefault();
@@ -503,6 +511,11 @@ export class SearchWidget extends Widget {
503511
}
504512

505513
private onReplaceInputKeyDown(keyboardEvent: IKeyboardEvent) {
514+
if (keyboardEvent.equals(ctrlKeyMod | KeyCode.Enter)) {
515+
this.searchInput.inputBox.insertAtCursor('\n');
516+
keyboardEvent.preventDefault();
517+
}
518+
506519
if (keyboardEvent.equals(KeyCode.Enter)) {
507520
this.submitSearch();
508521
keyboardEvent.preventDefault();

0 commit comments

Comments
 (0)