Skip to content

Commit b1ed036

Browse files
committed
fix: focus/blur thing
1 parent 401fc69 commit b1ed036

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

src/lib/editorManager.js

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,53 +1515,47 @@ async function EditorManager($header, $body) {
15151515
});
15161516
keyboardHandler.on("keyboardShow", scrollCursorIntoView);
15171517

1518-
// DOM event handlers for blur/focus and keydown
1519-
const domEventHandlersExtension = EditorView.domEventHandlers({
1520-
blur: async (_event, _view) => {
1521-
const { hardKeyboardHidden, keyboardHeight } =
1522-
await getSystemConfiguration();
1523-
const blur = () => {
1524-
const { activeFile } = manager;
1525-
if (activeFile) {
1526-
activeFile.focused = false;
1527-
activeFile.focusedBefore = false;
1528-
}
1529-
};
1530-
if (
1531-
hardKeyboardHidden === HARDKEYBOARDHIDDEN_NO &&
1532-
keyboardHeight < 100
1533-
) {
1534-
// external keyboard - blur immediately
1535-
blur();
1536-
return;
1537-
}
1538-
const onKeyboardHide = () => {
1539-
keyboardHandler.off("keyboardHide", onKeyboardHide);
1540-
blur();
1541-
};
1542-
keyboardHandler.on("keyboardHide", onKeyboardHide);
1543-
},
1544-
focus: (_event, _view) => {
1518+
// Attach native DOM event listeners directly to the editor's contentDOM
1519+
const contentDOM = editor.contentDOM;
1520+
1521+
contentDOM.addEventListener("focus", (_event) => {
1522+
const { activeFile } = manager;
1523+
if (activeFile) {
1524+
activeFile.focused = true;
1525+
}
1526+
});
1527+
1528+
contentDOM.addEventListener("blur", async (_event) => {
1529+
const { hardKeyboardHidden, keyboardHeight } =
1530+
await getSystemConfiguration();
1531+
const blur = () => {
15451532
const { activeFile } = manager;
15461533
if (activeFile) {
1547-
activeFile.focused = true;
1534+
activeFile.focused = false;
1535+
activeFile.focusedBefore = false;
15481536
}
1549-
},
1550-
keydown: (event, view) => {
1551-
if (event.key === "Escape") {
1552-
keydownState.esc = { value: true, target: view.contentDOM };
1553-
}
1554-
// Return false to allow default handling
1555-
return false;
1556-
},
1537+
};
1538+
if (
1539+
hardKeyboardHidden === HARDKEYBOARDHIDDEN_NO &&
1540+
keyboardHeight < 100
1541+
) {
1542+
// external keyboard - blur immediately
1543+
blur();
1544+
return;
1545+
}
1546+
// soft keyboard - wait for keyboard to hide
1547+
const onKeyboardHide = () => {
1548+
keyboardHandler.off("keyboardHide", onKeyboardHide);
1549+
blur();
1550+
};
1551+
keyboardHandler.on("keyboardHide", onKeyboardHide);
15571552
});
15581553

1559-
// Append the DOM event handlers extension to the editor
1560-
try {
1561-
editor.dispatch({
1562-
effects: StateEffect.appendConfig.of(domEventHandlersExtension),
1563-
});
1564-
} catch (_) {}
1554+
contentDOM.addEventListener("keydown", (event) => {
1555+
if (event.key === "Escape") {
1556+
keydownState.esc = { value: true, target: contentDOM };
1557+
}
1558+
});
15651559

15661560
updateMargin(true);
15671561
updateSideButtonContainer();

0 commit comments

Comments
 (0)