Skip to content

Flip prompt popover above the cursor when a scroll container would clip it - #5

Draft
shved270189 wants to merge 1 commit into
mainfrom
fix-prompt-popover-overflow
Draft

Flip prompt popover above the cursor when a scroll container would clip it#5
shved270189 wants to merge 1 commit into
mainfrom
fix-prompt-popover-overflow

Conversation

@shved270189

Copy link
Copy Markdown
Collaborator

Problem

The prompt/mention popover only flips above the cursor when it overflows the window (popoverRect.bottom > window.innerHeight). When a <lexxy-editor> lives inside a host container that clips overflow — e.g. a fixed-height scroll area or modal composer — the menu opens downward and is cut off by that container while the window still has room below.

Fix

Decide the flip against the editor's nearest clipping ancestor (the lowest visible bottom among ancestors whose overflow-y isn't visible), capped by the window, instead of the window alone. On a plain page there is no clipping ancestor, so the bound is window.innerHeight and behaviour is unchanged.

Comparing against contentRect.bottom would regress the common case: .lexxy-editor__content grows with content and has no overflow/max-height, so a downward menu on the last line always exceeds it and would flip up on a normal page. Walking to the real clipping ancestor avoids that.

Also in this change:

  • Clear data-clipped-at-bottom when the menu fits below again — the flip is re-evaluated from state-independent geometry on each reposition, so it toggles both ways without oscillating.
  • Reposition on scroll and visualViewport resize (rAF-throttled) so a pinned menu stays correctly placed as the editor scrolls or the viewport changes.
  • The menu still anchors once at the trigger and stays pinned there while the search term is typed (unchanged); only the vertical flip is dynamic.

Tests

New test/browser/tests/prompts/overflow_container.test.js + fixture: an editor inside a fixed-height scroll container with window room below. Verifies the menu flips above and stays within the container, and that the flip clears once the container has room again. Both assertions fail against the old window-only check.

Full prompts suite passes on chromium/firefox/webkit (the pre-existing macOS cursor_moves_away End-key failure is unaffected).

@shved270189
shved270189 requested a review from Copilot June 23, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants