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 #5170 and building on the node-transform approach suggested in #6718. This looks good to me: the clamp converges, runs inside the paste's own update (so one undo removes the paste and the clamp together), and the new tests fail on main and pass with the change. The suggestions below are optional and non-blocking.
-
The JSDoc says more than the code does (
packages/lexical-extension/src/TabIndentationExtension.ts, lines 79-80 and 108-110).@lexical/yjsapplies remote collaboration changes withskipTransforms: true(packages/lexical-yjs/src/SyncEditorStates.ts, lines 234, 542 and 570), so a remote paragraph at indent 9 stays at 9 on a peer withmaxIndent: 4. Likewise,setEditorStatere-runs element transforms only for a state that came fromparseEditorState. Suggested wording: the cap applies to local edits, pastes, the initial state and parsed states passed tosetEditorState; remote collaboration updates are not clamped. Leaving remote changes alone looks like the safer behaviour, so only the comments (and the PR description) need to change. -
Over-deep sublists of another list type lose their type and checked state (line 90, through
ListItemNode.setIndentand$handleOutdent). A check list nested past the limit under a bullet list comes out as plain bullets withcheckedcleared, and an<ol>under a<ul>becomes bullets. Text and order are kept, and Shift+Tab does the same thing to the same item, but here it happens on paste and when a stored document is opened. A sentence in theregisterTabIndentationJSDoc and a test that pins this result would make it an explicit choice. -
Nit: register the transforms untracked (lines 129-138).
registerNodeTransformmarks nodes dirty with aneditor.updatethat runs every element transform synchronously inside thiseffect, so a transform (or a$canIndent) that readssomeSignal.valuemakes the effect re-register, and re-mark the whole document dirty, whenever that signal changes. Wrapping the call inuntracked(() => registerMaxIndentTransforms(...))(already re-exported from./signals) avoids that. -
Nit: test plan output. AGENTS.md ("Commits and Pull Requests") asks for the real output of the command under
### After; the Before block is pasted, but the After run is only described.
| ): () => void { | ||
| const $clampIndent = (node: ElementNode) => { | ||
| if (node.getIndent() >= maxIndent && $getCanIndent()(node)) { | ||
| node.setIndent(maxIndent - 1); |
There was a problem hiding this comment.
Optional: for a list item this goes through ListItemNode.setIndent and $handleOutdent, which moves the item into the parent list. A check list (or <ol>) nested past the limit under a bullet list therefore comes out as bullets with checked cleared. Text and order survive, and Shift+Tab behaves the same, but it would be worth a sentence in the JSDoc and a test so it is an explicit choice.
…ension maxIndent on all content, including pastes maxIndent was only enforced by the INDENT_CONTENT_COMMAND handler, so a paste could bring in nested lists and indented blocks deeper than the limit. When maxIndent is set, register a transform on every element type that clamps indentation that the $canIndent predicate allows to below maxIndent, the same bound the indent command uses. Closes meta#5170 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>
…orrect the JSDoc Remote collaboration updates skip transforms and setEditorState only re-runs them for a parsed state, so say so. Register the transforms untracked so a signal read by a transform does not re-register them. Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ff08343 to
34faa81
Compare
|
Thanks for the review. Taken in the latest push:
I left the sublist type change on outdent as is, since Shift+Tab does the same to the same item. Also rebased onto — Ved Thakar |
There was a problem hiding this comment.
Thanks for picking up #5170 and building on the node-transform approach suggested in #6718. This looks good to me. The clamp converges and runs inside the paste's own update, so one undo removes the paste and the clamp together. The new tests fail on main and pass with the change. The last round's points are addressed: the JSDoc now says remote collaboration updates and unparsed setEditorState states are not clamped, and the registration runs untracked. Everything below is optional and non-blocking.
-
Over-deep sublists of another list type lose their type and checked state (
packages/lexical-extension/src/TabIndentationExtension.ts, line 91). For a list item,setIndentgoes through$handleOutdent, which moves the item into the parent list whatever its type. So a check list nested past the limit under a bullet list comes out as plain bullets withcheckedcleared, and a numbered sublist becomes bullets too. Text and order are kept, and Shift+Tab does the same thing, but here it happens on paste and when a saved document is opened. A sentence in theregisterTabIndentationJSDoc and a test that pins this result would make it an explicit choice. -
Add a
Verify:paragraph to the changeset (.changeset/max-indent-clamps-pasted-content.md). CONTRIBUTING.md ("Changesets") and.changeset/README.md("Behavior changes") ask for one when a fix changes observable behaviour, and this changes what pasted and loaded documents contain. Something like: "Verify: withmaxIndentset, paste a list nested deeper than the limit, or open a saved document that has one, and check it stops atmaxIndent - 1; a check or numbered sublist past the limit joins its parent list." -
Collaboration: the first local edit of a remote block can clamp it (same file, lines 80-81 and 110-111). Remote changes skip transforms, as the JSDoc now says. But a remote block deeper than this peer's limit is clamped as soon as a local update intentionally dirties it, for example by changing its alignment, though not by typing in it. That clamp then syncs to the other peers. The same happens document-wide when
maxIndentis registered after shared content has loaded. It only ever lowers indents, so peers converge. A short note in the JSDoc would help collaborative integrators expect it. -
Small description and docs drift. The PR description's "Scope" list still names "collaboration / remote updates". The comment in
packages/lexical-website/docs/extensions/signals.md(lines 106-108) saysregisterTabIndentationonly peeks atmaxIndent, but it now subscribes to the signal to re-register the transforms. -
Test plan output. AGENTS.md ("Commits and Pull Requests") asks for the real output of the command under
### After. The Before block is pasted, but the After run is only described.
| '@lexical/react': patch | ||
| --- | ||
|
|
||
| [fix] `maxIndent` of `TabIndentationExtension` and `TabIndentationPlugin` also limits indentation that arrives by paste, in the initial state or from code, not only by the Tab key |
There was a problem hiding this comment.
Optional: CONTRIBUTING.md ("Changesets") and .changeset/README.md ("Behavior changes") ask for a Verify: paragraph on a fix that changes observable behaviour. For example:
Verify: with `maxIndent` set, paste a list nested deeper than the limit, or open a saved document that has one, and check it stops at `maxIndent - 1`; a check or numbered sublist past the limit joins its parent list.| * the indent depth (indents below `maxIndent`), and `$canIndent` to control | ||
| * which elements may be indented. The `maxIndent` cap applies to local edits, | ||
| * pastes, the initial state and parsed states passed to `setEditorState`; | ||
| * remote collaboration updates are not clamped. Deeper indents already in the |
There was a problem hiding this comment.
Optional: remote updates skip transforms, but a remote block deeper than this peer's limit is clamped as soon as a local update intentionally dirties it, for example an alignment change, though not typing. That clamp then syncs to the other peers, and registering maxIndent after shared content has loaded clamps the whole document the same way. It only lowers indents, so peers converge; a sentence here would help collaborative integrators expect it.
Description
This solves issue #5170: pasted content can go deeper than
maxIndent.Builds on #6718 by @mdmuhtasimfuadfahim, reworked with node transforms as @etrepum suggested there.
Current behavior.
TabIndentationExtension(andregisterTabIndentation) only enforcesmaxIndentin itsINDENT_CONTENT_COMMANDhandler (newIndent < maxIndent).data-lexical-indent/padding-inline-start.maxIndent: 7, accepts a pasted list nested 10 levels deep.What this changes. The limit is enforced with node transforms rather than commands. When
maxIndentis set,registerTabIndentationregisters a transform on every registeredElementNodeclass exceptRootNode(it walkseditor._nodes, likeNormalizeInlineElementsExtension). The transform:setIndent(maxIndent - 1)when a node'sgetIndent()is>= maxIndentand the$canIndentpredicate allows it to indent. That is the same bound the indent command uses.ListItemNode.setIndent(), which outdents through$handleOutdent, so no item or text is lost. Items deeper than the limit end up as siblings at the deepest allowed level.maxIndentisnull(or0, which the command handler also treats as no limit). For a signal, the transforms are registered and removed with aneffectas the value changes.Scope: all content, not only pastes. Because these are transforms, the cap applies to any content that ends up in the document. That includes:
setEditorState;Registering also marks every element dirty, so the whole document is checked once at registration. An existing document saved with a deeper indent is therefore clamped when it is loaded with
maxIndentset. This is documented in the JSDoc of the transform helper and ofregisterTabIndentation.Legacy plugin. Since each registration now re-checks the whole document,
TabIndentationPluginkeeps$canIndentin a ref and passes a stable predicate. The effect now depends only on[editor, maxIndent], so an inline$canIndentarrow no longer re-registers on every render. The latest predicate is still the one used (it is stored in a ref set fromuseLayoutEffect). Changing$canIndentno longer re-clamps existing content: the new predicate applies the next time a node is transformed.Closes #5170
Test plan
New
packages/lexical-extension/src/__tests__/unit/IndentationLimitsPaste.test.ts(maxIndent: 4):1, 9from$initialEditorStatebecome1, 3.7becomes3.0, 1, 2, 3, 3, 3, 3, with every item's text kept.2, 10, 9become2, 3, 3.New
packages/lexical-react/src/__tests__/unit/LexicalTabIndentationPlugin.test.tsx:registerNodeTransformzero times, and the new predicate is the one applied.$canIndentprop is passed.The existing
IndentationLimits.test.ts(Tab / indent command) passes unchanged.Before
On
mainwith the tests applied and the source change reverted:With the plugin from before the ref change, "does not re-register when an inline $canIndent changes" fails.
After
On current
main:IndentationLimitsPaste.test.tsandLexicalTabIndentationPlugin.test.tsx: 9 passed (6 fail onmain). Chromium e2e:Indentation.spec.mjs,Tab.spec.mjsandList.spec.mjspass in full.pnpm run test-unit: all 9,580 tests passtsc,pnpm run flow(0 errors), and eslint/prettier on the changed files: cleanAuthor: Ved Thakar (@Vedthakar)
🤖 Generated with Claude Code