From 19aee5f262e9c16502e64c6090b4a41dfc5d0901 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:02:58 +0800 Subject: [PATCH] fix(app): Never show the webview's native context menu (#11) Right-clicks the app doesn't handle itself, such as on code-lens or inlay widgets inside the editor or in text fields, fell through to WebKit's own menu, whose Reload item reloads the whole app. Block it everywhere; the app's own menus already call preventDefault before this guard runs. Claude-Session: https://claude.ai/code/session_01B65qLEKnkeYTGdbwhLpjCu --- src/workbench/browserGuards.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/workbench/browserGuards.ts b/src/workbench/browserGuards.ts index 26c912c0..43d4f046 100644 --- a/src/workbench/browserGuards.ts +++ b/src/workbench/browserGuards.ts @@ -1,9 +1,9 @@ /** - * Makes the webview behave like a desktop app: no browser context menu - * outside text fields/editors, no reload/print/save-page/history shortcuts, - * no navigation on file drop. Copy/paste/undo stay untouched. + * Makes the webview behave like a desktop app: never the browser context menu + * (its Reload/AutoFill items would act on the webview), no reload/print/ + * save-page/history shortcuts, no navigation on file drop. Copy/paste/undo + * shortcuts stay untouched. */ -const EDITABLE = "input, textarea, [contenteditable=''], [contenteditable='true'], .cm-editor, .xterm"; const BLOCKED = new Set([ "Meta+P", @@ -35,12 +35,7 @@ function keyId(e: KeyboardEvent) { export function installBrowserGuards(opts: { blockReload?: boolean } = {}): () => void { const blockReload = opts.blockReload ?? import.meta.env.PROD; - const onContextMenu = (e: MouseEvent) => { - if (e.defaultPrevented) return; - const target = e.target as Element | null; - if (target?.closest?.(EDITABLE)) return; - e.preventDefault(); - }; + const onContextMenu = (e: MouseEvent) => e.preventDefault(); const onKeyDown = (e: KeyboardEvent) => { const id = keyId(e); if (BLOCKED.has(id) || (blockReload && RELOAD.has(id))) e.preventDefault();