Skip to content

[lexical][lexical-list][lexical-markdown] Feature: resetOnCopyNode configuration to NodeState and LexicalNode.resetOnCopyNodeFrom hook#8221

Merged
etrepum merged 6 commits intofacebook:mainfrom
etrepum:NodeState-resetOnCopy
Mar 13, 2026
Merged

[lexical][lexical-list][lexical-markdown] Feature: resetOnCopyNode configuration to NodeState and LexicalNode.resetOnCopyNodeFrom hook#8221
etrepum merged 6 commits intofacebook:mainfrom
etrepum:NodeState-resetOnCopy

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Mar 13, 2026

Description

It's often useful to use $copyNode to create a similar node to the current one, e.g. in implementations of insertNewAfter. In these cases there may be state that should get reset when copied, such as the checkmark state of a ListItemNode, or markdown parsing annotations.

LexicalNode

  • resetOnCopyFrom - a method similar to afterCloneFrom which can be used to reset a node's state

NodeState StateValueConfig

  • resetOnCopy - boolean configuration

List:

  • ListItemNode has been changed to use $copyNode in its implementation of insertNewAfter instead of a round-trip to JSON. The logic to uncheck the ListItemNode has been moved to its resetOnCopyFrom

Markdown:

  • listMarkerState and codeFenceState have been changed to use resetOnCopyNode: true

As an example, here's how the markdown parsing annotations have been updated to use this new configuration:

export const listMarkerState = createState('mdListMarker', {
  parse: (v) => (typeof v === 'string' && /^[-*+]$/.test(v) ? v : '-'),
  resetOnCopy: true,
});

Test plan

New unit tests, all existing unit and e2e pass unchanged

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 13, 2026 8:24pm
lexical-playground Ready Ready Preview, Comment Mar 13, 2026 8:24pm

Request Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 13, 2026
@etrepum etrepum changed the title [WIP][lexical] Feature: Add resetOnCopy configuration to NodeState and LexicalNode.resetOnCopyFrom hook [lexical] Feature: New resetOnCopyNode configuration for NodeState and LexicalNode.resetOnCopyNodeFrom hook Mar 13, 2026
@etrepum etrepum changed the title [lexical] Feature: New resetOnCopyNode configuration for NodeState and LexicalNode.resetOnCopyNodeFrom hook [lexical] Feature: resetOnCopyNode configuration to NodeState and LexicalNode.resetOnCopyNodeFrom hook Mar 13, 2026
@etrepum etrepum marked this pull request as ready for review March 13, 2026 19:00
@etrepum etrepum changed the title [lexical] Feature: resetOnCopyNode configuration to NodeState and LexicalNode.resetOnCopyNodeFrom hook [lexical][lexical-list][lexical-markdown] Feature: resetOnCopyNode configuration to NodeState and LexicalNode.resetOnCopyNodeFrom hook Mar 13, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 13, 2026
@etrepum etrepum added this pull request to the merge queue Mar 13, 2026
Merged via the queue into facebook:main with commit 66972c1 Mar 13, 2026
37 checks passed
levensta pushed a commit to levensta/lexical that referenced this pull request Mar 13, 2026
…nfiguration to NodeState and LexicalNode.resetOnCopyNodeFrom hook (facebook#8221)
@etrepum etrepum mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants