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

Text.equals extension/change #5733

Open
work-in-progress-danny opened this issue Sep 30, 2024 · 1 comment
Open

Text.equals extension/change #5733

work-in-progress-danny opened this issue Sep 30, 2024 · 1 comment

Comments

@work-in-progress-danny
Copy link
Contributor

Problem
When comparing two text nodes with Text.equals() , currently only text is omitted from the object when loose: true is provided. I want to compare two text nodes that will always have unique ids.

type TextNode = {
	id: string
	text: string
	bold?: boolean
	italic?: boolean
	underline?: boolean
}

Solution
I'm thinking of two possible solutions depending on the appetite of everyone.

  1. expose the isDeepEqual function from utils underlying the Text.equals check and let me roll my own equality function

or

  1. add an additional prop to the Text.equals function allowing me to pass in my own omission function something like
const omitTextAndIds = (obj: TextNode) => {
	const { text, id, ...rest } = obj
	return rest
}

Text.equals(nodeA, nodeB, {loose: true, omitFunc: omitTextAndIds})

Alternatives
I just run my own omit function on the nodes before I pass them into the equals function 🤔

@work-in-progress-danny
Copy link
Contributor Author

The alternative isn't really possible with the types

// @ts-ignore - I want to omit the id from the comparison but the function is expecting a complete TextNode
if (Text.equals(omitId(node), omitId(nextNode), { loose: true })) {
  Transforms.mergeNodes(editor, { at: nextPath })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant