Fix #83599. Refresh code widget focus state when hide

This commit is contained in:
Peng Lyu
2019-12-05 16:16:52 -08:00
parent c197f24c69
commit ca42425503
2 changed files with 25 additions and 0 deletions

View File

@@ -972,6 +972,7 @@ export const EventHelper = {
export interface IFocusTracker extends Disposable {
onDidFocus: Event<void>;
onDidBlur: Event<void>;
refreshState?(): void;
}
export function saveParentsScrollTop(node: Element): number[] {
@@ -1000,6 +1001,8 @@ class FocusTracker extends Disposable implements IFocusTracker {
private readonly _onDidBlur = this._register(new Emitter<void>());
public readonly onDidBlur: Event<void> = this._onDidBlur.event;
private _refreshStateHandler: () => void;
constructor(element: HTMLElement | Window) {
super();
let hasFocus = isAncestor(document.activeElement, <HTMLElement>element);
@@ -1026,9 +1029,24 @@ class FocusTracker extends Disposable implements IFocusTracker {
}
};
this._refreshStateHandler = () => {
let currentNodeHasFocus = isAncestor(document.activeElement, <HTMLElement>element);
if (currentNodeHasFocus !== hasFocus) {
if (hasFocus) {
onBlur();
} else {
onFocus();
}
}
};
this._register(domEvent(element, EventType.FOCUS, true)(onFocus));
this._register(domEvent(element, EventType.BLUR, true)(onBlur));
}
refreshState() {
this._refreshStateHandler();
}
}
export function trackFocus(element: HTMLElement | Window): IFocusTracker {