Files
radicle-desktop/src/lib/disableNativeContextMenu.ts
T
Rūdolfs Ošiņš 67108bd443 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.
2026-05-14 14:58:06 +02:00

18 lines
450 B
TypeScript

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();
});
}