Skip to content

fix: slash menu invisible in presentation mode#2018

Merged
harbournick merged 3 commits intosuperdoc-dev:mainfrom
asumaran:fix/slash-menu-position-presentation-mode
Feb 14, 2026
Merged

fix: slash menu invisible in presentation mode#2018
harbournick merged 3 commits intosuperdoc-dev:mainfrom
asumaran:fix/slash-menu-position-presentation-mode

Conversation

@asumaran
Copy link
Contributor

@asumaran asumaran commented Feb 13, 2026

Problem

The slash menu (/) was completely invisible in presentation mode (layout engine enabled). Pressing / would steal focus to the menu's hidden search input, blocking all typing, but the menu itself was rendered off-screen at ~left: -9900px.

Root cause: Editor.coordsAtPos() always used the ProseMirror view's coordinates, but in presentation mode the PM view is hidden off-screen (left: -9999px). The layout engine renders the visible content separately.

Fixes #781

Changes

  1. Editor.coordsAtPos: delegate to PresentationEditor.coordsAtPos() when available, which returns visual layout coordinates instead of hidden PM view coordinates.

  2. PresentationEditor.coordsAtPos: add caret geometry fallback via #computeCaretLayoutRect + denormalizeClientPoint for positions where getRangeRects returns empty (collapsed selections on empty lines).

  3. Slash menu plugin: add surface top-left fallback when coordsAtPos returns null (blank document before first layout). Set MENU_OFFSET_X to 0 so the menu aligns with the cursor.

Test plan

  • pnpm dev (layout engine ON by default)
  • Blank document: press /, menu appears at top-left of editor
  • Type several lines, press Enter for new line, press /, menu appears at cursor position
  • Right-click context menu still works as before
  • pnpm test, all 5545 tests pass

In presentation mode the ProseMirror view is hidden off-screen
(left: -9999px), so view.coordsAtPos() returns coordinates in
the hidden editor's space. Delegate to PresentationEditor.coordsAtPos()
which computes visual layout coordinates instead.

This was the root cause of the slash menu being positioned off-screen
when triggered via "/" in presentation mode.
getRangeRects returns empty for collapsed selections on empty lines
because there is no painted inline content to measure. Fall back to
#computeCaretLayoutRect which combines DOM position data with layout
metrics, then convert to viewport coordinates via denormalizeClientPoint.
Two fixes for slash menu positioning:

- Add fallback when coordsAtPos returns null (e.g. blank document
  before first layout): position the menu at the top-left of the
  visible editor surface instead of leaving coordinates at (0,0)
  which ends up off-screen after containing-block adjustment.

- Set MENU_OFFSET_X to 0 so the menu aligns with the cursor position.
  The previous 100px offset was never noticed because the menu was
  invisible in presentation mode.
@asumaran asumaran changed the title Fix/slash menu position presentation mode fix: slash menu invisible in presentation mode Feb 13, 2026
@tupizz tupizz self-requested a review February 13, 2026 21:09
Copy link
Contributor

@tupizz tupizz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @asumaran
Great work here, I tested locally and I loved it

Image

@harbournick
Copy link
Collaborator

@asumaran thanks for the PR! It looks good. It is still in 'draft' state - is that actually the case or do you want to mark it ready for review? thank you!

@harbournick harbournick self-requested a review February 13, 2026 23:07
@asumaran
Copy link
Contributor Author

@harbournick I believe this is ready to merge. The PR is still in draft because I was planing to run a few extra manual tests later, but since it’s already approved, feel free to merge if everything looks good on your side.

@asumaran asumaran marked this pull request as ready for review February 13, 2026 23:15
Copy link
Collaborator

@harbournick harbournick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the contribution! nice fix

@harbournick harbournick merged commit 513bc33 into superdoc-dev:main Feb 14, 2026
1 of 2 checks passed
@superdoc-bot
Copy link

superdoc-bot bot commented Feb 14, 2026

🎉 This PR is included in superdoc v1.13.0-next.11

The release is available on GitHub release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

why sometimes slash-menu-items doesn't exist

3 participants