mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-11-04 11:00:33 +08:00
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.
18 lines
450 B
TypeScript
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();
|
|
});
|
|
}
|