提交 5ff76dca 编写于 作者: B Benjamin Pasero

Open in background hotkey should only activate if cursor is at end of line (fixes #14350)

上级 6e44c83e
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册