Skip to content

fix: preserve block tooltip anchors during selection - #1221

Draft
vanilla-wave wants to merge 6 commits into
mainfrom
fix/editor-tooltip-reference
Draft

vanilla-wave wants to merge 6 commits into
mainfrom
fix/editor-tooltip-reference

Conversation

@vanilla-wave

@vanilla-wave vanilla-wave commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Selecting text inside nested editor blocks can make their toolbars flicker: Floating UI inserts a focus-return fallback beside its DOM reference, inside the ProseMirror document.

Use a shared EditorPopup for block toolbars and Markdown table cell controls. Focus management references the editor root while positioning references the selected block or cell. UIKit retains portals, placement, offsets, dismissal, and nested menus; no dependency versions or existing snapshots change.

Preserve the existing selection behavior when a block toolbar opens. The plugin view defers that transaction until the current update completes and discards it if the view, document, selection, anchor, focus, or visibility changes. React rendering no longer dispatches PM transactions. Selecting a block whose toolbar is already open keeps the existing node selection.

Regression coverage includes the entire pointer gesture (observation ends explicitly after mouse-up and popup stability), repeated selection, DOM identity, clipping, scrolling, Markdown table commands and menu keyboard navigation, Escape/Tab focus, deletion followed by typing, legacy-root reentrancy, and stale work after selection changes or destruction.

Validation:

  • Docker Chromium tests for tooltips, Markdown tables, selection scheduling, and original note snapshots.
  • Actual React 16.14 and 17.0.2: 8 compatibility scenarios pass; React 18 createRoot and legacy-root are covered by committed tests.
  • Consuming application's actual editor tested with the current build, UIKit 7.47.1 and unpatched Floating UI 0.27.19: repeated selection, clipping/portals, Escape, outside click, and deletion followed by typing pass. Restoring the unsafe DOM reference makes its regression test fail.
  • ESM/CJS builds, demo typecheck, ESLint and Prettier (one pre-existing non-null assertion warning).
  • Independent implementation and standards reviews completed; findings addressed.

Related: floating-ui/floating-ui#3504

Summary by Sourcery

Preserve editor popup anchors and selection behavior while preventing nested updates during block and table toolbar interactions.

Bug Fixes:

  • Prevent block and table toolbars from inserting focus-management elements into the ProseMirror document, eliminating tooltip flicker and preserving anchor DOM nodes during text selection.

Enhancements:

  • Share editor-aware popup positioning and focus management across block toolbars and Markdown table controls.
  • Preserve existing text and node selection behavior while safely deferring block-selection normalization and discarding stale updates after state, focus, anchor, visibility, or lifecycle changes.

Tests:

  • Add end-to-end coverage for popup anchoring, selection stability, scrolling, clipping, focus recovery, dismissal, deletion, table commands, keyboard navigation, React roots, and stale deferred work.
  • Strengthen existing note and code-block visual tests to verify selection and focus preservation and wait for asynchronous rendering.

@sourcery-ai

sourcery-ai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an editor-aware popup integration that keeps Floating UI focus fallbacks outside the ProseMirror document while preserving block text-selection behavior, and backs the fix with comprehensive tooltip, focus, selection, deletion, scrolling, and visual regression coverage.

File-Level Changes

Change Details Files
Introduce an editor-aware popup wrapper that separates focus management from block positioning.
  • Use the editor root as Floating UI’s focus-management reference while positioning against the selected block DOM element.
  • Replace direct block tooltip rendering with the wrapper while retaining UIKit popup behavior for portals, placement, dismissal, and nested interactions.
packages/editor/src/plugins/BaseTooltip/EditorPopup.tsx
packages/editor/src/plugins/BaseTooltip/index.tsx
Preserve ProseMirror selection and editing behavior when block toolbars open or blocks are removed.
  • Explicitly convert eligible non-atom node selections to text selections through a ProseMirror transaction.
  • Keep editor focus and allow continued typing after block deletion.
packages/editor/src/plugins/BaseTooltip/EditorPopup.tsx
demo/tests/visual-tests/EditorTooltips.visual.test.tsx
demo/tests/visual-tests/playground/Note.visual.test.tsx
Add regression coverage for tooltip anchoring, focus handling, DOM stability, and scrolling.
  • Verify repeated text selection keeps nested toolbars anchored without Floating UI fallback insertion or anchor replacement.
  • Cover Escape/Tab focus return, switching blocks, overflow clipping, scrolling, and deletion followed by typing.
  • Verify nested-note type changes preserve the existing selection and editor focus.
demo/tests/visual-tests/EditorTooltips.helpers.tsx
demo/tests/visual-tests/EditorTooltips.visual.test.tsx
demo/tests/visual-tests/playground/Note.visual.test.tsx
Make the empty code-block visual test wait for asynchronous markup rendering.
  • Replace a fixed timeout with an assertion on the rendered markup preview before taking the screenshot.
demo/tests/visual-tests/playground/CodeBlock.visual.test.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gravity-ui

gravity-ui Bot commented Sep 9, 2026

Copy link
Copy Markdown

Storybook Deployed

@gravity-ui

gravity-ui Bot commented Sep 9, 2026

Copy link
Copy Markdown

🎭 Playwright Report

@vanilla-wave
vanilla-wave marked this pull request as ready for review September 9, 2026 21:42

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@vanilla-wave
vanilla-wave marked this pull request as draft September 10, 2026 16:37
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.

1 participant