From 67108bd443c7ec28f3683444834da5d6020ef95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 14 May 2026 14:49:23 +0200 Subject: [PATCH] Disable native context menu Prevents the browser/webview default context menu app-wide, while preserving it for text selections and editable fields where the native menu is still useful. --- src/lib/disableNativeContextMenu.ts | 17 +++++++++++++++++ src/main.ts | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 src/lib/disableNativeContextMenu.ts diff --git a/src/lib/disableNativeContextMenu.ts b/src/lib/disableNativeContextMenu.ts new file mode 100644 index 000000000..e684121b1 --- /dev/null +++ b/src/lib/disableNativeContextMenu.ts @@ -0,0 +1,17 @@ +export function disableNativeContextMenu(): void { + window.addEventListener("contextmenu", event => { + const selection = window.getSelection(); + if ( + selection && + !selection.isCollapsed && + selection.toString().length > 0 + ) { + return; + } + const target = event.target as HTMLElement | null; + if (target?.closest("input, textarea, [contenteditable]")) { + return; + } + event.preventDefault(); + }); +} diff --git a/src/main.ts b/src/main.ts index 274e9a19a..ef77b7bbc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,12 @@ import { hotkeyKeyUX, hotkeyMacCompat, startKeyUX } from "keyux"; import { mount } from "svelte"; import App from "./App.svelte"; +import { disableNativeContextMenu } from "./lib/disableNativeContextMenu"; const app = mount(App, { target: document.body }); +disableNativeContextMenu(); + const mac = hotkeyMacCompat(); startKeyUX(window, [hotkeyKeyUX([mac])]);