diff --git a/frontend/app/view/webview/webview.tsx b/frontend/app/view/webview/webview.tsx index 39369e4daf..551f23bbb7 100644 --- a/frontend/app/view/webview/webview.tsx +++ b/frontend/app/view/webview/webview.tsx @@ -74,6 +74,7 @@ export class WebViewModel implements ViewModel { partitionOverride: PrimitiveAtom | null; userAgentType: Atom; env: WebViewEnv; + ctrlShiftUnsubFn: (() => void) | null = null; constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) { this.nodeModel = nodeModel; @@ -211,6 +212,11 @@ export class WebViewModel implements ViewModel { }); } + dispose() { + this.ctrlShiftUnsubFn?.(); + this.ctrlShiftUnsubFn = null; + } + get viewComponent(): ViewComponent { return WebView; } @@ -508,18 +514,21 @@ export class WebViewModel implements ViewModel { return true; } const ctrlShiftState = globalStore.get(getSimpleControlShiftAtom()); - if (ctrlShiftState) { + if (ctrlShiftState && !this.ctrlShiftUnsubFn) { // this is really weird, we don't get keyup events from webview - const unsubFn = globalStore.sub(getSimpleControlShiftAtom(), () => { + this.ctrlShiftUnsubFn = globalStore.sub(getSimpleControlShiftAtom(), () => { const state = globalStore.get(getSimpleControlShiftAtom()); if (!state) { - unsubFn(); + this.ctrlShiftUnsubFn?.(); + this.ctrlShiftUnsubFn = null; const isStillFocused = globalStore.get(this.nodeModel.isFocused); if (isStillFocused) { this.webviewRef.current?.focus(); } } }); + } + if (ctrlShiftState) { return false; } this.webviewRef.current?.focus();