Skip to content

Commit 4805c59

Browse files
authored
minor, fix double sub in webview giveFocus (#3110)
1 parent 645424a commit 4805c59

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

frontend/app/view/webview/webview.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class WebViewModel implements ViewModel {
7474
partitionOverride: PrimitiveAtom<string> | null;
7575
userAgentType: Atom<string>;
7676
env: WebViewEnv;
77+
ctrlShiftUnsubFn: (() => void) | null = null;
7778

7879
constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) {
7980
this.nodeModel = nodeModel;
@@ -211,6 +212,11 @@ export class WebViewModel implements ViewModel {
211212
});
212213
}
213214

215+
dispose() {
216+
this.ctrlShiftUnsubFn?.();
217+
this.ctrlShiftUnsubFn = null;
218+
}
219+
214220
get viewComponent(): ViewComponent {
215221
return WebView;
216222
}
@@ -508,18 +514,21 @@ export class WebViewModel implements ViewModel {
508514
return true;
509515
}
510516
const ctrlShiftState = globalStore.get(getSimpleControlShiftAtom());
511-
if (ctrlShiftState) {
517+
if (ctrlShiftState && !this.ctrlShiftUnsubFn) {
512518
// this is really weird, we don't get keyup events from webview
513-
const unsubFn = globalStore.sub(getSimpleControlShiftAtom(), () => {
519+
this.ctrlShiftUnsubFn = globalStore.sub(getSimpleControlShiftAtom(), () => {
514520
const state = globalStore.get(getSimpleControlShiftAtom());
515521
if (!state) {
516-
unsubFn();
522+
this.ctrlShiftUnsubFn?.();
523+
this.ctrlShiftUnsubFn = null;
517524
const isStillFocused = globalStore.get(this.nodeModel.isFocused);
518525
if (isStillFocused) {
519526
this.webviewRef.current?.focus();
520527
}
521528
}
522529
});
530+
}
531+
if (ctrlShiftState) {
523532
return false;
524533
}
525534
this.webviewRef.current?.focus();

0 commit comments

Comments
 (0)