mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 11:50:42 +08:00
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.
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
@@ -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])]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user