Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks for the selection toolbar. Approval is on hold because no current spec governs a new public RichText component like RichTextEditorSelectionToolbar: its props, the Alt+F10 and Escape interaction, placement, hosting and the docked touch presentation. An engineering owner needs to provide or identify that governing spec and records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. These need fixing whatever that decision is:
- The toolbar is positioned DOM with
zIndex: 2instead of a Layer surface, whichspec:AST-027FR7 and FR8 require for floating surfaces, and anoverflow: hiddenancestor cuts it off. - When the page scrolls the selection out of view, the toolbar stays pinned at the top of the viewport over unrelated content, because
selectionToolbarPlacementalways clamps it into view. - The docked bar positions itself from the visual viewport instead of measuring the keyboard the way
architecture:react-component-runtimeINV11 requires outside Core. - At 2,740 changed lines the pull request is over the 2,000-line scope limit, and landing the link-popover extraction on its own first would bring it under.
[Automated review]
RichTextEditorSelectionToolbar, rendered in RichTextEditor's plugins slot, shows formatting beside a non-collapsed selection while the editor is editable: bold, italic, underline, strikethrough, inline code, and Link, with the same commands, glyphs, and link popover as RichTextEditorToolbar, then any endContent. A selection of table cells gets the formats without Link. It never takes focus when it appears. Alt+F10 moves focus into it, arrow keys move along it, and Escape returns focus to the editor with the selection kept. It renders beside the editable text and overlays the document without reflowing it, by the selection's focus on the side away from the selected text. Under a coarse pointer it docks to the bottom of the visual viewport; presentation keeps either surface on every device. Read-only and disabled editors show none. The toolbar's link popover moves into a module both toolbars share, and its inline formats and glyph resolver are shared with the new toolbar; neither is exported from the package. Co-authored-by: Emily Horsman <[email protected]>
557e18a to
9277ad4
Compare
5b3b7f8 to
c97e31f
Compare
There was a problem hiding this comment.
Thanks for the selection toolbar. Approval is on hold because no current spec governs a new public RichText component like RichTextEditorSelectionToolbar: its props, when it shows, the Alt+F10 and Escape keys, placement, hosting, the docked touch presentation and its look. An engineering owner needs to provide or identify that governing spec and records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. These need fixing whatever that decision is:
- The toolbar is positioned DOM with
zIndex: 2instead of a Layer surface, whichspec:AST-027FR7 and FR8 require for floating surfaces, so anoverflow: hiddenancestor cuts it off. - When the page scrolls the selection out of view, the toolbar stays pinned at the top of the viewport, where a press formats words the writer cannot see.
- The focus and drag tracking copies
LinkCard's; one shared RichText hook, installed from the editor's root listener, should serve both. - The
isShownRefEffect synchronizes no external system, and the docked bar measures the keyboard from the visual viewport rather than asarchitecture:react-component-runtimeINV11 asks outside Core. - At 2,739 changed lines the pull request is over the 2,000-line scope limit; landing the link-popover extraction on its own first brings it under.
[Automated review]
The toolbar was absolutely positioned DOM placed by script, so an ancestor that clips its overflow cut it off and it stayed pinned at the viewport edge when the selection scrolled away. It is now a core useLayer context layer, CSS-anchored to a one-pixel box that sits at the selection inside the element that positions the editable text. The box moves only when the selection or the text's layout changes; the toolbar follows it with CSS, scrolls with the text, and hides while the selection is out of view. The docked touch presentation and its `presentation` prop are out: a bar above the on-screen keyboard is its own affordance. The toolbar's keys register with the editor only while it shows, so no Effect mirrors its shown state into a ref. Co-authored-by: Ernest Tien <[email protected]>
Takes #8718's shared link popover, URL form, and inline-format helpers (from #11189) in place of this branch's own extraction, and its useEditorFocusAndDrag in place of this toolbar's own focus and drag tracking. Table selections read their formats here, since the shared helper covers range and node selections. Co-authored-by: Ernest Tien <[email protected]>
There was a problem hiding this comment.
Thanks for the selection toolbar, which now hosts through Layer and no longer pins to the viewport edge. Approval is on hold because AST-106 admits a selection format bar as a RichText plugin but leaves its exact options, events and visuals to a decision not yet recorded: the props and their defaults, when the bar shows, Alt+F10, Escape and Cmd/Ctrl+K, placement, table selections and the "Selected text" name. An engineering owner needs to provide or identify that governing spec (an AST-106 amendment or a component spec) and record the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner.
These need fixing whatever that decision is:
- The bar adds its own editor update listener and root
ResizeObserver(RichTextEditorSelectionToolbar.tsx:446-484) instead of placing through RichText's sharedregisterEditorReposition, which the link popover plugin, code block headers and task checkboxes already use. - During a mouse drag the bar re-measures the selection and rewrites its anchor on every selection change while it is hidden (14 times in one three-line drag), which
architecture:react-component-runtimeINV18 rules out; measuring only while the bar shows, through the shared scheduler, fixes it. - The description still describes a
presentationprop, aRichTextEditorSelectionToolbarPresentationexport, a docked touch bar, a non-Layer host and a 21-test suite, none of which the code ships, so it needs rewriting to match the code. - The title's
richtextscope names no component and## Scopehas noComponents:line, so addComponents: RichTextEditorSelectionToolbar(or scope the title to it) for the new export and its two types.
| useEffect( | ||
| () => | ||
| mergeRegister( | ||
| editor.registerEditableListener(editable => setIsEditable(editable)), | ||
| editor.registerUpdateListener(({editorState}) => { | ||
| const next = editorState.read($readFacts); | ||
| if (!sameFacts(factsRef.current, next)) { | ||
| factsRef.current = next; | ||
| setFacts(next); | ||
| } | ||
| placeAtSelection(next); | ||
| }), | ||
| ), | ||
| [editor, placeAtSelection], | ||
| ); | ||
|
|
||
| // Text that wraps differently (a narrower field, a font that loads) moves | ||
| // the selection inside the editor, so the anchor moves with it. Syncs with | ||
| // the root element Lexical attaches. | ||
| useEffect(() => { | ||
| if (typeof ResizeObserver === 'undefined') { | ||
| return; | ||
| } | ||
| const observer = new ResizeObserver(() => | ||
| placeAtSelection(factsRef.current), | ||
| ); | ||
| const unregister = editor.registerRootListener((next, previous) => { | ||
| if (previous != null) { | ||
| observer.unobserve(previous); | ||
| } | ||
| if (next != null) { | ||
| observer.observe(next); | ||
| } | ||
| }); | ||
| return () => { | ||
| unregister(); | ||
| observer.disconnect(); | ||
| }; | ||
| }, [editor, placeAtSelection]); |
There was a problem hiding this comment.
This update listener and the ResizeObserver Effect below re-create what registerEditorReposition (editorReposition.ts) already owns: "the one reposition scheduler for chrome placed beside the editable text", measuring once per frame after an editor update, a root resize or a window resize. CodeBlockHeaderPlugin, TaskCheckboxPlugin and RichTextEditorLinkPopoverPlugin call it, so a fix there would miss this bar. Keep this listener for the selection facts only. Place the anchor once as the bar shows, then call registerEditorReposition(editor, () => placeAtSelection(factsRef.current)) while it shows, as RichTextEditorLinkPopoverPlugin.tsx:497-511 does, and delete the ResizeObserver Effect.
| factsRef.current = next; | ||
| setFacts(next); | ||
| } | ||
| placeAtSelection(next); |
There was a problem hiding this comment.
This runs on every editor update, including each selection change while a pointer drags, and the bar is hidden then (!isDragging at line 409). Each call reads the range's client rects and the frame's box, then writes the anchor's top/left/height. In Chromium, one drag over three lines made 60 pointer moves, 15 selection changes and 14 placements, all with the bar hidden. architecture:react-component-runtime INV18 keeps layout reads off such paths. Measuring only while the bar shows, through the shared scheduler, fixes it.
| endContent?: ReactNode; | ||
| } | ||
|
|
||
| /** Room between the toolbar and the selection, and inside its band. */ |
There was a problem hiding this comment.
Non-blocking (INV29): "and inside its band" describes the band clamp this head removed. Suggest: /** Room between the toolbar and the selection. */
| }; | ||
| }, [editor, placeAtSelection]); | ||
|
|
||
| // Shows the anchored layer while the toolbar is shown. |
There was a problem hiding this comment.
Non-blocking (INV29): this restates the code. A note that names the system keeps only the reason, for example // Syncs the native popover with whether the bar shows.
…TabLinks A first version keeps only the options RichTextEditorToolbar already has with the same meaning and default. formats, endContent, and label are removed: the bar offers all five formats and names itself from the catalog. Co-authored-by: Ernest Tien <[email protected]>
Takes #8717's non-scaling wrapper anchor and useToolbarLink's buttonRef. The selection toolbar's Link button gets the same wrapper, so its link popover anchors to a box a press never scales. Co-authored-by: Ernest Tien <[email protected]>
There was a problem hiding this comment.
Thanks for the selection toolbar, which now offers only the two options RichTextEditorToolbar already has. Approval is on hold because spec:AST-106 admits a selection format bar as a RichText plugin but leaves its exact options, events and visuals to a decision not yet recorded: the hasLink and hasNewTabLinks props and their defaults, when the bar shows, Alt+F10, Escape and Cmd/Ctrl+K, placement, table selections and the "Selected text" name. An engineering owner needs to provide or identify that governing spec (an AST-106 amendment or a component spec) and record the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner.
These need fixing whatever that decision is:
- The bar adds its own editor update listener and root
ResizeObserver(RichTextEditorSelectionToolbar.tsx:420-458) instead of placing through RichText's sharedregisterEditorReposition, which the link popover plugin, code block headers and task checkboxes already use. - During a mouse drag the bar re-measures the selection and rewrites its anchor on every selection change while it is hidden (6 times in one three-line drag), which
architecture:react-component-runtimeINV18 rules out; measuring only while the bar shows, through the shared scheduler, fixes it. - The description lists
formats,label,endContentand aRichTextEditorSelectionToolbarFormatexport that the code no longer ships, so its Controls, Public delta and Testing parts need rewriting to the two props it has. - Miss: the "With selection toolbar" story says the bar docks to the bottom of the screen under a coarse pointer (
RichTextEditor.stories.tsx:194-195), but it floats beside the selection there too, so that sentence needs removing. - The title's
richtextscope names no component and## Scopehas noComponents:line, so addComponents: RichTextEditorSelectionToolbar(or scope the title to it) for the new export and its props type.
| * moves focus into it and Escape returns to the selection. Under a coarse | ||
| * pointer it docks to the bottom of the screen. |
There was a problem hiding this comment.
Miss from the last review: this head has no docked presentation. Under a coarse pointer at 390 px the bar floats beside the selection like any other, so readers of the story are told about a mode that does not exist. Suggest dropping the last sentence:
/**
* Formatting beside selected text, from the `plugins` slot. Alt+F10 (⌥F10)
* moves focus into it and Escape returns to the selection.
*/| 'sharedEditorTheme', | ||
| 'URL_MATCHER', | ||
| 'EMAIL_MATCHER', | ||
| 'selectionToolbarPlacement', |
There was a problem hiding this comment.
Non-blocking: nothing in the package defines selectionToolbarPlacement (placement is the module-local placeAnchor), so this name can never be exported and the check can never fail. Dropping it, and "the selection toolbar's placement" from the index.ts header, keeps both honest.
Brings the link popover plugin's retarget onto main. Main moved ToolbarLinkPopover under internal/, so the selection toolbar imports it from there.
There was a problem hiding this comment.
Thanks for the selection toolbar. Approval is on hold because spec:AST-106 admits a selection format bar as a RichText plugin but leaves its exact options, events and visuals to a decision not yet recorded: the hasLink and hasNewTabLinks props and their defaults, when the bar shows, Alt+F10, Escape and Cmd/Ctrl+K, placement, table selections and the "Selected text" name. An engineering owner needs to provide or identify that governing spec (an AST-106 amendment or a component spec) and record the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner.
These need fixing whatever that decision is:
- The bar adds its own editor update listener and root
ResizeObserver(RichTextEditorSelectionToolbar.tsx:420-458) instead of placing through RichText's sharedregisterEditorReposition, which the link popover plugin, code block headers and task checkboxes already use. - During a mouse drag the bar re-measures the selection and rewrites its anchor on every selection change while it is hidden (6 times in one three-line drag), which
architecture:react-component-runtimeINV18 rules out; measuring only while the bar shows, through the shared scheduler, fixes it. - The description lists
formats,label,endContentand aRichTextEditorSelectionToolbarFormatexport that the code does not ship, so its Controls, Public delta and Testing parts need rewriting to the two props it has. - The "With selection toolbar" story says the bar docks to the bottom of the screen under a coarse pointer (
RichTextEditor.stories.tsx:225-226), but it floats beside the selection there too, so that sentence needs removing. - The title's
richtextscope names no component and## Scopehas noComponents:line, so addComponents: RichTextEditorSelectionToolbar(or scope the title to it) for the new export and its props type. - Newly live check:
architecture:component-import-boundariesINV10 asks a pull request that adds an optional feature to report the first-load gzip delta of a page that renders the component without it, so the description needs that base-against-head number for aRichTextEditorpage without the bar.
Claims and files checked
Review mode: full; reason: author-not-engowner
- Claim: the richtext changeset's bar (five formats and Link, never takes focus, Alt+F10, arrows, Escape, overlays without reflow, unclipped, read-only and disabled show none, two props plus base props and ref, a translated name): verified in code, unit tests and a Chromium run of the story.
- Claim: the core changeset's new "Selected text" message: verified in the English catalog.
- Claim: the description's
formats,label,endContentand format-type export: false; the code hashasLinkandhasNewTabLinksonly. - Claim: the description's test count (49 files, 803 tests): stale; the RichText suites now run 52 files and 860 tests, all passing.
- Claim: Cmd/Ctrl+K opens the bar's link form only when the top toolbar does not take it, and table selections get no Link: verified by unit tests.
- Claim: no docked presentation: verified in code and at a 390 px touch width; the story still says otherwise.
- File:
RichTextEditorSelectionToolbar.tsx: shared-scheduler and drag-measurement findings; stale header and constant comments (non-blocking). - File:
RichTextEditor.stories.tsx: docking sentence finding. - File:
index.ts: header names a placement module that does not exist (non-blocking). - File:
publicSurface.test.ts: checks a name nothing defines (non-blocking). - Files: both changesets,
README.md,RichTextEditor.doc.mjs,en.json,RichTextEditorSelectionToolbar.test.tsx, the Chromium spec andRichTextEditorToolbarLink.test.tsx: clear.
| * selection shows while the editor is editable, and its props and format | ||
| * type. |
There was a problem hiding this comment.
Non-blocking (INV29), missed in an earlier review: no format type is exported any more (index.ts:54-55 exports the component and its props type). Suggest:
* selection shows while the editor is editable, and its props.
User need
A writer formats words where they are working. In a long
RichTextEditordocument, or in one with no top toolbar, applying bold or a link to selected text means reaching the toolbar at the top of the field, or knowing the shortcut. Document editors put formatting beside the selection. RichText could not, because a caller cannot position UI against the selection inside the editor without reaching into Lexical's DOM.Problem and solution fit
RichTextEditorSelectionToolbar, a plugin added throughRichTextEditor'spluginsslot. The editor gains no prop.endContentafter a divider.RichTextEditorToolbar's own format commands,richtext:*glyph keys, and link popover (shared through refactor(richtext): share the toolbar's link popover and format helpers #11189), anchored to this toolbar's Link button.Toolbar, so it hasrole="toolbar", a translated label ("Selected text"), and roving focus.aria-keyshortcuts="Alt+F10"announces this.RichTextEditorToolbartook the key first.useLayer, context mode). A one-pixel anchor sits at the selection's focus inside the element that positions the editable text, as tall as the selected lines, and CSS anchor positioning keeps the toolbar beside it: above a one-line selection or one made upwards, below one made downwards over lines, flipping when there is no room.@astryxdesign/corechangeset; doc.mjs guidance, the README,index.ts,publicSurface.test.ts, the story "With selection toolbar", unit tests, and a browser spec.Current specification
pluginsprop, and neitherRichTextEditornorRichTextViewgains a prop. FR7: every control is reachable by keyboard from the selection and named for assistive technology. FR6: its chrome overlays the document. FR8: it needs no caller services.architecture:internationalizationINV1a: its label is in the catalog.architecture:public-component-apiINV5: its ownaria-keyshortcutscannot be overwritten by caller props.presentationprop.Public delta and caller burden
RichTextEditorSelectionToolbar, plus the typesRichTextEditorSelectionToolbarPropsandRichTextEditorSelectionToolbarFormat.formats(which formats appear, in order),hasLink,hasNewTabLinks(match the toolbar's value),label,endContent, and base props andref.Design and alternatives
RichTextEditorToolbarmode. One toolbar would render in two places, and its Selector and history controls do not belong beside a selection.ContextMenuuses for its cursor anchor.overflow: hiddenancestor clips and which stays pinned at the viewport edge when the selection scrolls away.Evidence
Red arm:
RichTextEditorSelectionToolbar.test.tsxon the parent branch cannot import the module, so no tests run.Real-browser screenshots: the browser spec below runs in CI once the stack retargets to
main. The stills previously posted here showed the earlier script-placed version and its docked presentation, so they are withdrawn; current desktop and phone stills follow from that run.Scope
Testing
pnpm exec vitest run packages/richtext/: 49 files, 803 tests pass. The selection toolbar's suite covers:formats,hasLink, andendContent;RichTextEditorToolbar;pnpm check:repo) pass.overflow: hiddenancestor does not clip it; and at a 390 px phone width it fits and moves no paragraph.Co-authored by @ernestt (original author) and @cixzhang.
Owner and land path
Owner: the Astryx fix loop, lane 3. Carried by lane 3 for the contributor. Waits on the owner's decision for the selection toolbar; after it, Specs, CodeBunny and green CI; the drain merges.