提交 db21446a 编写于 作者: B Benjamin Pasero

missing focus when triggering search while quick open is open (fixes #6668)

上级 e08b4bd9
......@@ -34,7 +34,7 @@ export interface IQuickOpenCallbacks {
onCancel: () => void;
onType: (value: string) => void;
onShow?: () => void;
onHide?: () => void;
onHide?: (focusLost?: boolean) => void;
onFocusLost?: () => boolean /* veto close */;
}
......@@ -67,6 +67,12 @@ export class QuickOpenController extends DefaultController {
}
}
enum HideReason {
ELEMENT_SELECTED,
FOCUS_LOST,
CANCELED
}
const DEFAULT_INPUT_ARIA_LABEL = nls.localize('quickOpenAriaLabel', "Quick picker. Type to narrow down results.");
export class QuickOpenWidget implements IModelProvider {
......@@ -121,7 +127,7 @@ export class QuickOpenWidget implements IModelProvider {
if (keyboardEvent.keyCode === KeyCode.Escape) {
DOM.EventHelper.stop(e, true);
this.hide(true);
this.hide(HideReason.CANCELED);
}
})
.on(DOM.EventType.CONTEXT_MENU, (e: Event) => DOM.EventHelper.stop(e, true)) // Do this to fix an issue on Mac where the menu goes into the way
......@@ -418,7 +424,7 @@ export class QuickOpenWidget implements IModelProvider {
// Hide if command was run successfully
if (hide) {
this.hide();
this.hide(HideReason.ELEMENT_SELECTED);
}
}
......@@ -662,7 +668,7 @@ export class QuickOpenWidget implements IModelProvider {
return height;
}
public hide(isCancel: boolean = false): void {
public hide(reason?: HideReason): void {
if (!this.isVisible()) {
return;
}
......@@ -672,7 +678,7 @@ export class QuickOpenWidget implements IModelProvider {
this.builder.domBlur();
// report failure cases
if (isCancel) {
if (reason === HideReason.CANCELED) {
if (this.model) {
let entriesCount = this.model.entries.filter(e => this.isElementVisible(this.model, e)).length;
if (this.usageLogger) {
......@@ -702,14 +708,14 @@ export class QuickOpenWidget implements IModelProvider {
}
// Callbacks
if (isCancel) {
if (reason === HideReason.CANCELED) {
this.callbacks.onCancel();
} else {
this.callbacks.onOk();
}
if (this.callbacks.onHide) {
this.callbacks.onHide();
this.callbacks.onHide(reason === HideReason.FOCUS_LOST);
}
}
......@@ -840,7 +846,7 @@ export class QuickOpenWidget implements IModelProvider {
const veto = this.callbacks.onFocusLost && this.callbacks.onFocusLost();
if (!veto) {
this.hide(false /* Do not treat loosing focus as cancel! */);
this.hide(HideReason.FOCUS_LOST);
}
});
}
......
......@@ -290,8 +290,10 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
onCancel: () => { /* ignore, handle later */ },
onType: (value: string) => { /* ignore, handle later */ },
onShow: () => this.emitQuickOpenVisibilityChange(true),
onHide: () => {
this.restoreFocus(); // focus back to editor or viewlet
onHide: (focusLost?: boolean) => {
if (!focusLost) {
this.restoreFocus(); // focus back to editor unless user clicked somewhere else
}
this.emitQuickOpenVisibilityChange(false); // event
}
}, {
......@@ -429,8 +431,10 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
onShow: () => {
this.emitQuickOpenVisibilityChange(true); // event
},
onHide: () => {
this.restoreFocus(); // focus back to editor or viewlet
onHide: (focusLost?: boolean) => {
if (!focusLost) {
this.restoreFocus(); // focus back to editor unless user clicked somewhere else
}
this.emitQuickOpenVisibilityChange(false); // event
}
});
......@@ -524,7 +528,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.inQuickOpenMode.set(true);
this.emitQuickOpenVisibilityChange(true);
},
onHide: () => {
onHide: (focusLost?: boolean) => {
this.inQuickOpenMode.reset();
// Complete promises that are waiting
......@@ -532,7 +536,9 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.promisesToCompleteOnHide.pop()(true);
}
this.restoreFocus(); // focus back to editor or viewlet
if (!focusLost) {
this.restoreFocus(); // focus back to editor unless user clicked somewhere else
}
this.emitQuickOpenVisibilityChange(false);
}
}, {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册