mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
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
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user