Skip to content

Add pass option to Editor.nodes #5843

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

12joan
Copy link
Contributor

@12joan 12joan commented Apr 14, 2025

Description
Adds the pass option from Node.nodes to Editor.nodes, making it possible to skip the descendants of certain nodes while keeping the match predicate simple and efficient.

Example

const isUnmarkable = (node: Node) => Element.isElement(node) && node.type === 'code-block';

const markableLeaves = Array.from(Editor.nodes(editor, {
  at: [],
  match: Text.isText,
  // Skips all leaves inside unmarkable nodes
  pass: ([node]) => isUnmarkable(node),
}));

Context
As per the behaviour of Node.nodes, passed nodes may still be returned from Editor.nodes if none of their ancestors were passed. I've modified the test for Node.nodes to make it clearer from reading the test that this is the intended behaviour.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@12joan 12joan force-pushed the feat/editor-nodes-pass branch from e9e1996 to a66a4f2 Compare April 14, 2025 19:01
Copy link

changeset-bot bot commented Apr 14, 2025

🦋 Changeset detected

Latest commit: a66a4f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dylans dylans merged commit 63c0db5 into ianstormtaylor:main Apr 15, 2025
7 of 11 checks passed
@github-actions github-actions bot mentioned this pull request Apr 4, 2025
dylans pushed a commit to dylans/slate that referenced this pull request Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants