Skip to content

Flip prompt popover when it overflows the editor content rect (minimal proper fix) - #6

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

Flip prompt popover when it overflows the editor content rect (minimal proper fix)#6
shved270189 wants to merge 1 commit into
mainfrom
fix-prompt-popover-overflow-minimal

Conversation

@shved270189

@shved270189 shved270189 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Problem

The prompt/mention popover only flips above the cursor when it would overflow the window (popoverRect.bottom > window.innerHeight). When a <lexxy-editor> lives inside a 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 even though the window still has room below it.

Fix

Flip the menu above the cursor when the popover would overflow the editor's nearest clipping ancestor (an ancestor whose overflow-y is not visible), capped by the window — instead of checking the window alone:

#availableBottom() {
  let bottom = window.innerHeight
  let node = this.#editorElement

  while (node && node !== document.body && node !== document.documentElement) {
    if (getComputedStyle(node).overflowY !== "visible") {
      bottom = Math.min(bottom, node.getBoundingClientRect().bottom)
    }
    node = node.parentElement
  }

  return bottom
}

When the editor has no clipping ancestor the bound is window.innerHeight, so an ordinary editor keeps the menu below the cursor exactly as before — the flip only kicks in when something would actually clip it.

Tests

New test/browser/tests/prompts/overflow_container.test.js + fixture, covering both directions:

  • editor inside a fixed-height scroll container with the window still having room below → menu flips above the cursor and stays within the container;
  • the same editor with no clipping ancestor → menu stays below the cursor (guards against flipping when nothing clips).

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

@shved270189
shved270189 requested a review from Copilot June 24, 2026 11:05

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.

@shved270189
shved270189 force-pushed the fix-prompt-popover-overflow-minimal branch 3 times, most recently from 41d796a to d3aef8f Compare June 24, 2026 12:15
@shved270189
shved270189 force-pushed the fix-prompt-popover-overflow-minimal branch from d3aef8f to 2c68c51 Compare June 24, 2026 12:52
@shved270189
shved270189 marked this pull request as ready for review June 24, 2026 12:55
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