Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
Thanks for picking up #9454. The reconciler change is a nice general fix: a block that ends in an inline element whose last child is a LineBreakNode now gets the managed <br>, so links that end in a line break draw their empty line too. The new tests also fail on main and pass here.
One issue needs fixing before this lands.
A line break or paragraph typed inside the overflow splits the paragraph (packages/lexical-overflow/src/index.ts, insertNewAfter). OverflowNode.insertNewAfter() still delegates to parent.insertNewAfter(). While the node was a block, nothing called that method to split the overflow. Now that the node is inline, $splitNodeAtPoint in packages/lexical/src/LexicalSelection.ts splits it by calling insertNewAfter(), and the delegation creates a new paragraph. To reproduce, set the character limit to 5, type 1234567, press ArrowLeft, then:
| Keys | main |
this PR |
|---|---|---|
Shift+Enter (rich) or Enter (plain), then x |
123456⏎x7 in one paragraph |
123456⏎x, with 7 in a new paragraph |
Enter (rich), then x |
123456 / x7 |
123456 / x / 7 |
This reproduces with real key presses in Chromium and Firefox (vitest browser mode). If the node splits itself, as LinkNode.insertNewAfter does, the main behaviour comes back and all of this PR's tests still pass:
insertNewAfter(_: RangeSelection, restoreSelection = true): null | LexicalNode {
const overflow = $copyNode(this);
this.insertAfter(overflow, restoreSelection);
return overflow;
}Please also add these mid-overflow cases to CharacterLimit.test.ts: Shift+Enter, Enter and Backspace with the caret inside the overflow rather than at its end. #9454 asked for them, and AGENTS.md puts caret and selection behaviour in browser tests.
Optional, non-blocking suggestions:
$hoistSelectionAfterTrailingLineBreak(packages/lexical-react/src/shared/useCharacterLimit.ts): no test fails when its call is removed. The selection already lands at(paragraph, 2)once$mergePreviousremoves the merged-away overflow. Either add a case that needs the call or drop it.- A block decorator at the root past the limit, such as a horizontal rule, now gets wrapped in the inline
OverflowNode. The core root transform then puts it inside a paragraph, and it stays asparagraph > horizontalruleafter the text drops back under the limit.mainalready misbehaves on that path (an update loop), but skipping non-inline leaves inneedsOverflowParentwould avoid both problems. packages/lexical/src/LexicalStructure.tsstill describesOverflowNodeas inline content "although itsisInline()is false", so that comment needs updating. I would keep theisOverflowClassexemption, becauseallows()is what keeps an inline overflow legal directly under the root.- Nit:
isInline(): truenarrows the return type, so a subclass that overridesisInline(): booleanstops type-checking. DeclaringisInline(): booleanavoids that. - Nit: AGENTS.md asks the test plan's Before and After sections to paste the real command output rather than describe it.
… inline without the line break caret regression OverflowNode.isInline() now returns true (meta#6027, reverted in meta#6535). The revert was caused by a trailing LineBreakNode inside the now inline OverflowNode: the browser can't put the caret after a <br> that ends an inline element, so the next character landed before the line break. - The reconciler gives a block the managed trailing <br> when its last child is an inline element that itself ends with a LineBreakNode. - $wrapOverflowedNodes moves a caret left at the end of an OverflowNode ending with a line break to the same spot just after the OverflowNode. Closes meta#9454 Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r paragraph is inserted inside it Now that OverflowNode is inline, $splitNodeAtPoint splits it through insertNewAfter, which still delegated to the parent and so made a new paragraph. Make the other half of the overflow, as LinkNode does. Add browser tests for Shift+Enter, Enter and Backspace with the caret inside the overflow, and drop $hoistSelectionAfterTrailingLineBreak, which no test needed. Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
46d1e96 to
27c6429
Compare
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
27c6429 to
6a98ab8
Compare
|
Thanks for the review. Fixed in the latest push, which also resolves the conflict with
I did not change the block-decorator-past-the-limit case, which already misbehaves on — Ved Thakar |
There was a problem hiding this comment.
This looks good to me. Thanks for the quick turnaround on the last round. OverflowNode.insertNewAfter now splits the overflow itself, as LinkNode does, so Enter and Shift+Enter with the caret inside overflowed text behave as they do on main. The new mid-overflow browser cases cover that path. The reconciler change is a nice general fix too: any block that ends in an inline element whose last child is a LineBreakNode now gets the managed <br>, so a link ending in a line break draws its empty line as well. The new tests cover both halves of the fix. Without the insertNewAfter split the mid-overflow Shift+Enter and Enter cases fail, and without the reconciler change the end-of-overflow line-break cases fail.
All of the following are optional and non-blocking:
-
Changeset
Verify:paragraph (.changeset/overflow-node-inline.md). This fix changes observable DOM and editing behaviour. Blocks that end in an inline element with a trailing line break gain a managed<br>in the rendered DOM, andOverflowNode.isInline()andinsertNewAfter()now behave like an inline element's. The "Changesets" section of AGENTS.md and the "Behavior changes" section of.changeset/README.mdask for aVerify:paragraph in that case, for example:Verify: rendered-DOM snapshots of blocks that end in a link or other inline element whose last child is a line break, and code that calls insertNewAfter() or isInline() on an OverflowNode.
-
Backspace at the overflow boundary (
packages/lexical-playground/src/__tests__/browser/CharacterLimit.test.ts). #9454's plan lists "backspace across the boundary". The new Backspace case puts the caret between6and7, inside the overflow. A case with the caret between5and6would cover the boundary itself. -
Block decorator past the limit. Understood that you left this out of scope because
mainalready misbehaves there. For the record, with the wrapper now inline, a horizontal rule past the limit ends up asparagraph > horizontalruleand stays that way once the text drops back under the limit. Skipping non-inline leaves inneedsOverflowParent(packages/lexical-react/src/shared/useCharacterLimit.ts) would avoid it, and a follow-up issue would do. -
Stale comments.
packages/lexical/src/LexicalStructure.ts(theisOverflowClassandINTERNAL_isInlineContentdoc comments) andpackages/lexical-y/src/internal/Structure.ts($isHeldInline) still say thatOverflowNode'sisInline()is false. I'd keep theisOverflowNodeexemption inallows(), though, because it is what keeps an inline overflow legal directly under the root when the structure is enforced. -
Test plan. The "Commits and Pull Requests" section of AGENTS.md asks for the command you ran plus its real Before/After output, rather than a description of the results.
| 'lexical': patch | ||
| --- | ||
|
|
||
| [fix] `OverflowNode` is an inline node, so text past the character limit stays on the same line, and a block that ends in an inline element whose last child is a line break shows its empty last line |
There was a problem hiding this comment.
Optional: this fix changes observable output (a managed <br> in the rendered DOM of blocks ending in an inline element with a trailing line break, and OverflowNode.isInline() / insertNewAfter() now behave as an inline element's), so the "Changesets" section of AGENTS.md and "Behavior changes" in .changeset/README.md ask for a Verify: paragraph, e.g.:
Verify: rendered-DOM snapshots of blocks that end in a link or other inline element whose last child is a line break, and code that calls insertNewAfter() or isInline() on an OverflowNode.| expect(getText()).toBe(isRichText ? '123456\n\nx7' : '123456\nx7'); | ||
| }); | ||
|
|
||
| test('Backspace deletes the character before the caret', async () => { |
There was a problem hiding this comment.
Optional: this case deletes inside the overflow (caret between 6 and 7), and it passes with or without the insertNewAfter change. #9454's plan also lists "backspace across the boundary", so a case with the caret between 5 and 6 (the start of the overflow) would cover that too.
Description
This solves issue #9454.
OverflowNodeis now inline (isInline()returnstrue), as #6027 first tried. #6535 reverted #6027 because, in plain-text mode or with Shift+Enter in rich text, a line break typed at the end of the overflow left the caret before the trailingLineBreakNode.Root cause. Once
OverflowNodeis inline, a<br>ends up as the last thing inside an inline<span>at the end of a paragraph. Two things then go wrong:<br>only when a block's direct last child is aLineBreakNode. Here the paragraph's last child is theOverflowNode, so no managed<br>is added and the new empty line has no caret position.OverflowNode, past its<br>. The browser can't put the caret there and moves it to before the overflow, so the next character goes in front of the6. The test saw76instead of6<br>7.Changes
lexical-overflow:OverflowNode.isInline()returnstrue.lexical(reconciler):$isLastChildLineBreakOrDecoratoralso counts aLineBreakNodereached through trailing inline elements, so that block gets the managed<br>. This also fixes the same layout for other inline elements, such as aLinkNodeending with a line break. Decorators are unchanged.lexical-overflow:OverflowNode.insertNewAfter()makes the other half of the overflow with$copyNode, asLinkNodedoes. Now that the node is inline,$splitNodeAtPointsplits it through this method, and delegating to the parent made a new paragraph for a line break or paragraph typed inside the overflow.NodeStructureExtension.test.ts: the [lexical][lexical-code-core][lexical-devtools][lexical-extension][lexical-link][lexical-list][lexical-mark][lexical-mdast][lexical-rich-text][lexical-table][lexical-website] Feature: Experimental node structure in $config (inline, children, mergeAdjacent, derived) and an opt-in NodeStructureExtension #9452 assertion now expectsoverflow.isInline()to betrue. Follow-up for maintainers: theisOverflowClass/isOverflowNodeexemptions inLexicalStructure.tscould probably be removed now; this PR leaves them alone.Closes #9454
Test plan
Before
isInline()alone (the Fix OverflowNode configuration #6027 configuration),packages/lexical-playground/src/__tests__/browser/CharacterLimit.test.ts(vitest browser, chromium): 6 failed | 10 passed (16). This is the Revert "Fix OverflowNode configuration" #6535 regression: the caret lands before the line break in plain text, and thedelete text in frontcases fail.packages/lexical-react/src/__tests__/unit/useLexicalCharacterLimit.test.tsagainstmain: 3 failed | 7 passed (10).packages/lexical/src/__tests__/unit/LexicalReconciler.test.ts(a paragraph ending in aLinkNodewhose last child is aLineBreakNode) againstmain: 1 failed. No managed<br>is rendered after the<a>.After
On this branch, rebased onto current
main:CharacterLimit.test.ts(browser, Chromium): 32 passed, including the new cases with the caret inside the overflow (Shift+Enter, Enter and Backspace between the6and7of12345[67], rich and plain text, both charsets). 8 of those 12 fail without theinsertNewAfterchange.useLexicalCharacterLimit.test.ts,LexicalReconciler.test.ts,NodeStructureExtension.test.tsand thelexical-overflowtests (unit): 301 passed.tsc,tsc-test, eslint and prettier on the changed files: clean. Firefox and WebKit were not run locally.Author: Ved Thakar (@Vedthakar)
🤖 Generated with Claude Code