[lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an internal ephemeral node concept #7904
+222
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Some of the ugly parts in JSON + HTML export are related to dealing with partially selected TextNode. This tries to clean up some of those rough edges with a new internal concept.
Ephemeral Nodes
An ephemeral node is marked with the
node[EPHEMERAL] === true
(it is a symbol so is non-enumerable and won't show up with yjs). These instances always returnthis
forgetLatest
andgetWritable
and are not allowed to be in an EditorState (which means they can not be a parent or child of some other node). You can create these with$cloneWithPropertiesEphemeral
. This is mostly used to create a TextNode in a read-only context where we slice its__text
based on the selection.With this feature we can be more sure that state doesn't leak from these cloned nodes back into the EditorState, and that EditorState doesn't leak out into the accessors and mutators of the ephemeral node (e.g.
setTextContent
now works on these ephemeral nodes in a read-only editor with no errors or side-effects to the EditorState)Test plan
New unit tests, all existing e2e + unit tests should pass