Skip to content

Commit 2b79ca8

Browse files
committed
fix: scope native context-menu disabling to CodeMirror focus only
1 parent 2a00c09 commit 2b79ca8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/lib/applySettings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export default {
2323
});
2424

2525
system.setInputType(appSettings.value.keyboardMode);
26-
system.setNativeContextMenuDisabled(true);
26+
// Keep native context menu enabled globally; editor manager scopes disabling to CodeMirror focus.
27+
system.setNativeContextMenuDisabled(false);
2728
},
2829
afterRender() {
2930
const { value: settings } = appSettings;

src/lib/editorManager.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ async function EditorManager($header, $body) {
104104
let autosaveTimeout = null;
105105
let touchSelectionController = null;
106106
let touchSelectionSyncRaf = 0;
107+
let nativeContextMenuDisabled = null;
108+
109+
const setNativeContextMenuDisabled = (disabled) => {
110+
const value = !!disabled;
111+
if (nativeContextMenuDisabled === value) return;
112+
nativeContextMenuDisabled = value;
113+
const api = globalThis.system?.setNativeContextMenuDisabled;
114+
if (typeof api !== "function") return;
115+
try {
116+
api.call(globalThis.system, value);
117+
} catch (error) {
118+
console.warn("Failed to update native context menu state", error);
119+
}
120+
};
107121

108122
const { scrollbarSize } = appSettings.value;
109123
const events = {
@@ -1599,8 +1613,13 @@ async function EditorManager($header, $body) {
15991613

16001614
// Attach native DOM event listeners directly to the editor's contentDOM
16011615
const contentDOM = editor.contentDOM;
1616+
const isFocused =
1617+
contentDOM === document.activeElement ||
1618+
contentDOM.contains(document.activeElement);
1619+
setNativeContextMenuDisabled(isFocused);
16021620

16031621
contentDOM.addEventListener("focus", (_event) => {
1622+
setNativeContextMenuDisabled(true);
16041623
const { activeFile } = manager;
16051624
if (activeFile) {
16061625
activeFile.focused = true;
@@ -1609,6 +1628,7 @@ async function EditorManager($header, $body) {
16091628
});
16101629

16111630
contentDOM.addEventListener("blur", async (_event) => {
1631+
setNativeContextMenuDisabled(false);
16121632
touchSelectionController?.setMenu(false);
16131633
const { hardKeyboardHidden, keyboardHeight } =
16141634
await getSystemConfiguration();

0 commit comments

Comments
 (0)