Skip to content

Commit ca42425

Browse files
committed
Fix microsoft#83599. Refresh code widget focus state when hide
1 parent c197f24 commit ca42425

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/vs/base/browser/dom.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ export const EventHelper = {
972972
export interface IFocusTracker extends Disposable {
973973
onDidFocus: Event<void>;
974974
onDidBlur: Event<void>;
975+
refreshState?(): void;
975976
}
976977

977978
export function saveParentsScrollTop(node: Element): number[] {
@@ -1000,6 +1001,8 @@ class FocusTracker extends Disposable implements IFocusTracker {
10001001
private readonly _onDidBlur = this._register(new Emitter<void>());
10011002
public readonly onDidBlur: Event<void> = this._onDidBlur.event;
10021003

1004+
private _refreshStateHandler: () => void;
1005+
10031006
constructor(element: HTMLElement | Window) {
10041007
super();
10051008
let hasFocus = isAncestor(document.activeElement, <HTMLElement>element);
@@ -1026,9 +1029,24 @@ class FocusTracker extends Disposable implements IFocusTracker {
10261029
}
10271030
};
10281031

1032+
this._refreshStateHandler = () => {
1033+
let currentNodeHasFocus = isAncestor(document.activeElement, <HTMLElement>element);
1034+
if (currentNodeHasFocus !== hasFocus) {
1035+
if (hasFocus) {
1036+
onBlur();
1037+
} else {
1038+
onFocus();
1039+
}
1040+
}
1041+
};
1042+
10291043
this._register(domEvent(element, EventType.FOCUS, true)(onFocus));
10301044
this._register(domEvent(element, EventType.BLUR, true)(onBlur));
10311045
}
1046+
1047+
refreshState() {
1048+
this._refreshStateHandler();
1049+
}
10321050
}
10331051

10341052
export function trackFocus(element: HTMLElement | Window): IFocusTracker {

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
874874

875875
public onHide(): void {
876876
this._modelData?.view.refreshFocusState();
877+
this._focusTracker.refreshState();
877878
}
878879

879880
public getContribution<T extends editorCommon.IEditorContribution>(id: string): T {
@@ -1806,6 +1807,12 @@ class CodeEditorWidgetFocusTracker extends Disposable {
18061807
public hasFocus(): boolean {
18071808
return this._hasFocus;
18081809
}
1810+
1811+
public refreshState(): void {
1812+
if (this._domFocusTracker.refreshState) {
1813+
this._domFocusTracker.refreshState();
1814+
}
1815+
}
18091816
}
18101817

18111818
const squigglyStart = encodeURIComponent(`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' enable-background='new 0 0 6 3' height='3' width='6'><g fill='`);

0 commit comments

Comments
 (0)