Skip to content

feat(bubble): drive the selection bubble without registerPlugin (P0) - #130

Open
HMarzban wants to merge 15 commits into
mainfrom
feat/bubble-controller
Open

HMarzban wants to merge 15 commits into
mainfrom
feat/bubble-controller

Conversation

@HMarzban

Copy link
Copy Markdown
Contributor

Summary

This is phase P0 of the approved bubble and quick insert design (spec §12.1, BQ2 and BQ3).

The desktop selection bubble no longer mounts Tiptap's React <BubbleMenu>. That component calls editor.registerPlugin from the lazy bubble chunk, which rebuilt all 29 plugin views after the editor was already interactive.

A framework-free BubbleController, in the same lazy chunk, now:

  • listens to editor events, with an O(1) early exit while you type;
  • positions one reused root with the shared @floating-ui/dom;
  • keeps the DOM contract: the root is appended on show and removed synchronously on hide, with data-smart-bubble, data-state and one role="toolbar".

Depends on #124 (the spec and plan this PR cites). Merge #124 first.

What changes for writers

  • Anchor (BQ3): a selection that wraps lines now centres the bubble on the selected part of its first line. Before, it centred on the box between the selection's two ends.
  • Select all: the bubble now appears, on the first visible line.
  • Whitespace: a selection of only spaces no longer shows the bubble.
  • Unchanged: the items, the Esc fade, Alt+F10, the colour popover, Paint format and the status pill.

Sizes

Production build, scripts/check-editor-chunk-size.ts:

Chunk Before (gz) After (gz) Change
Editor chunk 393,172 B 393,171 B −1 B
Bubble chunk 12,238 B 9,798 B −2,440 B, because @tiptap/extension-bubble-menu is no longer imported

Screenshots

A two-line selection: main on the left, this branch on the right.

main this branch
Light
Dark
RTL

Test plan

  • Unit: bubble-controller.test.ts and selection-bubble-rules.test.ts (100 pass). They cover the 250 ms show delay, the IME composition skip, dragstart and contextmenu, drag-then-pointerup, blur rules, setEditable, idempotent destroy, the RTL band-edge probe, and the textblock-bounded anchor.
  • E2E (Chromium): the selection-bubble, lazy-surfaces, paint-format, toolbar-focus-guards and editor-leak suites (83 pass, 2 skipped by environment, as before). New cases:
    • no plugin registered after the chunk lands (plugin-view identity);
    • a wrapped selection and a selection starting at a paragraph's end, both of which fail on the old anchor;
    • select all, cold and warm;
    • whitespace-only selection;
    • dragstart;
    • a tab switch leaves no root and no listeners;
    • a collaborator deletes the selection while a bubble item has focus;
    • Esc on a bubble item plays the 90 ms fade.
  • bun run test (1730 pass), typecheck, lint and check (only the 7 existing warnings).
  • Reviews: a task review per task, one fix round on Task 0.3, a whole-branch review and its fix wave; all findings are closed.
  • Design review with screenshots, run by the owner session.

Notes

  • Contract amendment A18 is recorded in docs/superpowers/specs/2026-11-13-smart-toolbar-v1-contract.md.
  • Follow-ups for P1:
    • A collaborator typing nonstop restarts the 250 ms show delay. Tiptap's plugin does the same, so this is not a regression.
    • shouldShowBubble reads the whole document's text on remote changes while select all is active.
  • RTL: the band-edge probe is covered by unit tests only.

🤖 Generated with Claude Code

The controller tests asserted "now shown" 50 ms after the 250 ms show
delay (30 ms after the 60 ms reposition debounce). In Bun's shared test
process a late timer made them flaky; they now poll with a 1 s ceiling.
A range starting on a block boundary (select all from 0, or a band hit
between blocks) holds that whole block, so getClientRects returned its
border box as the first line. intoTextblock moves both ends into a
textblock first; coordsAtPos reads those positions too.

Under the last selected line the bubble left the view when the
selection runs past the band's bottom, or when there is no room for it
there: the bottom side then anchors under the first line that shows.
Mod-A makes an AllSelection, which shouldShowBubble rejected as not a
TextSelection. Spec 7.2 has the bubble show for select all, anchored to
the first selected line that is visible.
Moves listenerCounts out of editor-leak.spec.ts into a helper, so the
selection bubble's tab-switch test can count the same listeners.
SelectionBubbleView no longer renders Tiptap's BubbleMenu, which called
registerPlugin from the lazy bubble chunk and rebuilt every plugin view
when it landed. A BubbleController per editor shows, hides and
positions one reused root through a portal; the DOM contract is
unchanged (appended to the scroll container on show, removed on hide).

The BUBBLE_KEY meta, the requestAnimationFrame re-append workaround and
the opacity focus-out guard go. Placement changes reposition only when
the side changes, and a selection made before the chunk landed shows at
once.

New e2e cases: no plugin is registered on mount, the anchor on a wrapped
second line and on select all, whitespace-only selections, dragstart, a
tab switch with the bubble open, and a collaborator deleting the
selection.
Adds amendment A18 to the smart toolbar v1 contract and the Unreleased
CHANGELOG entry, with the measured editor and bubble chunk sizes.
A start at a textblock's end (a drag begun past the line end, or a band
hit in the gap after a paragraph) kept the measured range open over the
next blocks, and getClientRects returned their whole border boxes, so
the first line became a whole block. The scan now reads one textblock
per range, skipping ends and empty textblocks, within the 300-position
budget; the bottom side mirrors it.

The kept-timer unit test now checks the bubble shows before a full
show delay after the no-op transaction.
The wrapped-line case now selects across the wrap and compares the
centre with the top line's part only. A selection starting at a
paragraph's end must anchor to the next line's text, and select all is
also checked with multi-line paragraphs, the band edge in a gap and
inside one.
…edges

Focus coming back to the editor (Esc on a bubble item) re-evaluated at
once and hid the suppressed bubble 5 ms in, cutting its 90 ms exit fade.
The plugin debounced that path; focus now re-evaluates only while the
bubble is hidden, and compositionend stays immediate.

hide() resets the root's visibility, so a re-shown root waits for its
first position instead of showing at the old one. The band-edge probe
reads both inline edges and keeps the smaller position, so a
right-to-left line is read from its start.
Esc on a bubble item must leave data-closing for the fade before the
root goes. The collaborator case now deletes the selection while a
bubble item has focus, expects the editor focused afterwards, and a new
selection to show the bubble again (no suppression left behind).
The anchor change is horizontal centring on the selected part of the
first line and no whole-block anchoring, not a fix for covering the
line above. Re-measured after the review fixes: editor chunk group
393,171 B gz (-1 B against main), bubble chunk 9,798 B gz (-2,440 B).

This branch has not been deployed

No deployments
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