Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][lexical[lexical-utils] Feature: NodeCaret abstraction for traversals and ranges #7046

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Jan 13, 2025

Description

NOTE: This is a work in progress, not a finalized proposal

A fair amount of bugs and complexity in our code results from ambiguity and awkwardness around traversing the node tree, as well as issues around coordinates becoming stale after mutations. This is a draft in-progress proposal for a new set of abstractions that can be used in place of the typical PointType and RangeSelection to work through these sorts of traversal use cases with hopefully fewer bugs.

There are two major deficiencies that the design of NodeCaret hopes to address:

  • PointType is not directional, and it's also not possible to infer a direction from a collapsed RangeSelection.
  • Dealing with the borders of an ElementNode is full of quirks, especially when empty, frequently causing over-selection or under-selection or just having to frequently branch for empty and non-empty cases.
  • Instability of PointType when doing anything "before" the point (e.g. inserting a node before a point "moves" the logical location of the point to the newly inserted node)

At this time there's no special support for TextNode. A NodeCaret is a triple of:

  • type: 'breadth' | 'depth'
  • origin: LexicalNode - the "anchor" of this caret
  • direction: 'next' if the caret points after this node (towards the next sibling for breadth, towards the first child for depth) and 'previous' if the caret points before this node (towards the previous sibling for breadth, towards the last child for depth)

Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 5:55am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 5:55am

@facebook-github-bot facebook-github-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 Jan 13, 2025
Copy link

github-actions bot commented Jan 13, 2025

size-limit report 📦

Path Size
lexical - cjs 30.45 KB (+4.88% 🔺)
lexical - esm 30.28 KB (+4.9% 🔺)
@lexical/rich-text - cjs 39.4 KB (+3.78% 🔺)
@lexical/rich-text - esm 30.92 KB (+0.02% 🔺)
@lexical/plain-text - cjs 37.97 KB (+3.99% 🔺)
@lexical/plain-text - esm 28.23 KB (+0.35% 🔺)
@lexical/react - cjs 41.21 KB (+3.57% 🔺)
@lexical/react - esm 32.36 KB (+0.23% 🔺)

@etrepum etrepum changed the title [WIP][lexical[lexical-utils] Feature: NodeCaret abstraction for traversals and ranges [WIP][Breaking Change][lexical[lexical-utils] Feature: NodeCaret abstraction for traversals and ranges Jan 14, 2025
@etrepum etrepum changed the title [WIP][Breaking Change][lexical[lexical-utils] Feature: NodeCaret abstraction for traversals and ranges [WIP][lexical[lexical-utils] Feature: NodeCaret abstraction for traversals and ranges Jan 14, 2025
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants