Skip to content

Commit c66c9ce

Browse files
committed
fix(mdviewer): slash menu positioned at right edge instead of cursor
The horizontal-overflow clamp in show() wrote a viewport coordinate to menu.style.left, but .slash-menu is position:absolute inside a position:fixed anchor — left is anchor-relative, not viewport-relative. The menu jumped to viewport x ≈ (cursor.x + 895) and stayed there because show() never reset menu.style.left between opens, letting the stale value re-trigger the clamp on every subsequent /. - Reset menu.style.left at the start of show() - Convert the clamp from viewport coords to anchor-relative
1 parent 6275b71 commit c66c9ce

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ function show() {
231231
anchor.style.left = rect.left + "px";
232232
anchor.style.top = rect.bottom + 4 + "px";
233233

234+
// Reset menu offset — values are anchor-relative, so stale ones from a
235+
// previous open would shift the menu away from the new cursor position.
236+
menu.style.left = "";
237+
234238
anchor.classList.add("visible");
235239
menu.scrollTop = 0;
236240
visible = true;
@@ -251,10 +255,13 @@ function show() {
251255
menu.style.bottom = "0";
252256
}
253257

254-
// Clamp horizontal
258+
// Clamp horizontal. menu.style.left is an offset from the anchor
259+
// (the anchor is position:fixed and acts as the containing block),
260+
// so a viewport coordinate must be converted before assigning.
255261
const menuRect = menu.getBoundingClientRect();
256262
if (menuRect.right > window.innerWidth - 8) {
257-
menu.style.left = Math.max(8, window.innerWidth - menuRect.width - 8) + "px";
263+
const clampedViewportLeft = Math.max(8, window.innerWidth - menuRect.width - 8);
264+
menu.style.left = (clampedViewportLeft - rect.left) + "px";
258265
}
259266
});
260267
}

src-node/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)