From 5ff76dca8594f13e265eca3604a326c88b915083 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 25 Oct 2016 15:32:26 +0200 Subject: [PATCH] Open in background hotkey should only activate if cursor is at end of line (fixes #14350) --- .../quickopen/browser/quickOpenWidget.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts index 1f3b578f1e3..a1192053e05 100644 --- a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts +++ b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts @@ -152,6 +152,7 @@ export class QuickOpenWidget implements IModelProvider { DOM.addDisposableListener(this.inputBox.inputElement, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => { const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e); + const shouldOpenInBackground = this.shouldOpenInBackground(keyboardEvent); // Do not handle Tab: It is used to navigate between elements without mouse if (keyboardEvent.keyCode === KeyCode.Tab) { @@ -165,13 +166,13 @@ export class QuickOpenWidget implements IModelProvider { this.navigateInTree(keyboardEvent.keyCode, keyboardEvent.shiftKey); } - // Select element on Enter - else if (keyboardEvent.keyCode === KeyCode.Enter || keyboardEvent.keyCode === KeyCode.RightArrow) { + // Select element on Enter or on Arrow-Right if we are at the end of the input + else if (keyboardEvent.keyCode === KeyCode.Enter || shouldOpenInBackground) { DOM.EventHelper.stop(e, true); const focus = this.tree.getFocus(); if (focus) { - this.elementSelected(focus, e, keyboardEvent.keyCode === KeyCode.RightArrow ? Mode.OPEN_IN_BACKGROUND : Mode.OPEN); + this.elementSelected(focus, e, shouldOpenInBackground ? Mode.OPEN_IN_BACKGROUND : Mode.OPEN); } } @@ -304,6 +305,18 @@ export class QuickOpenWidget implements IModelProvider { return this.builder.getHTMLElement(); } + private shouldOpenInBackground(e: StandardKeyboardEvent): boolean { + if (e.keyCode !== KeyCode.RightArrow) { + return false; // only for right arrow + } + + if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) { + return false; // no modifiers allowed + } + + return this.inputBox.inputElement.selectionStart === this.inputBox.value.length; // only when cursor is at the end of the input field value + } + private onType(): void { const value = this.inputBox.value; -- GitLab