Skip to content

Commit 90a303a

Browse files
committed
fix(mdviewer): forward F-keys to Phoenix, scroll slash menu selection,
refocus editor after popup dismiss on Escape - Forward function keys (F1-F12) to Phoenix keybinding manager - Slash menu arrow navigation now scrolls selected item into view - Escape with any popup open refocuses the editor after dismissal - Check slash menu, lang picker, link popover before forwarding Escape
1 parent ad999c0 commit 90a303a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src-mdviewer/src/bridge.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,23 @@ export function initBridge() {
156156

157157
document.addEventListener("keydown", (e) => {
158158
if (e.key === "Escape") {
159-
// Don't forward Escape to Phoenix if search bar or other UI is open
160-
const searchBar = document.getElementById("search-bar");
161-
if (searchBar && searchBar.classList.contains("open")) {
162-
return; // let search handle it
159+
// Don't forward Escape to Phoenix if any popup/overlay is open
160+
const popupSelectors = [
161+
"#search-bar.open",
162+
"#slash-menu.visible",
163+
"#lang-picker.visible",
164+
"#link-popover.visible"
165+
];
166+
const hasOpenPopup = popupSelectors.some(sel => document.querySelector(sel));
167+
if (hasOpenPopup) {
168+
// Let the popup handle Escape, then refocus editor
169+
setTimeout(() => {
170+
const content = document.getElementById("viewer-content");
171+
if (content && getState().editMode) {
172+
content.focus({ preventScroll: true });
173+
}
174+
}, 0);
175+
return;
163176
}
164177
sendToParent("embeddedEscapeKeyPressed", {});
165178
return;

src-mdviewer/src/components/slash-menu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,15 @@ function handleKeydown(e) {
378378
e.stopImmediatePropagation();
379379
selectedIndex = (selectedIndex + 1) % filteredItems.length;
380380
renderItems();
381+
const sel = menu.querySelector(".slash-menu-item.selected");
382+
if (sel) sel.scrollIntoView({ block: "nearest" });
381383
} else if (e.key === "ArrowUp") {
382384
e.preventDefault();
383385
e.stopImmediatePropagation();
384386
selectedIndex = (selectedIndex - 1 + filteredItems.length) % filteredItems.length;
385387
renderItems();
388+
const sel = menu.querySelector(".slash-menu-item.selected");
389+
if (sel) sel.scrollIntoView({ block: "nearest" });
386390
} else if (e.key === "Enter") {
387391
e.preventDefault();
388392
e.stopImmediatePropagation();

0 commit comments

Comments
 (0)