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

fix: properly handle VariableNode deletion in Lexical #1120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

loicguillois
Copy link
Collaborator

This pull request includes several updates to the useVariablePlugin function in the frontend/src/components/RichEditor/useVariablePlugin.ts file to improve whitespace handling around VariableNode elements. The most important changes include adding a new utility function for cleaning up whitespace, updating the node insertion logic, and modifying the mutation listener.

Whitespace handling improvements:

  • Added the cleanUpWhitespace function to ensure proper whitespace handling around VariableNode elements.
  • Updated the isWhitespaceBefore and isWhitespaceAfter functions to handle cases where the node is null or contains whitespace at the start or end of the text content.

Node insertion logic:

  • Updated the useVariablePlugin function to insert whitespace before and after a VariableNode if necessary, ensuring proper spacing.

Mutation listener:

  • Modified the useEffect hook to register a mutation listener that cleans up whitespace when a VariableNode is detached.

Additional imports:

  • Added the $getNodeByKey import from lexical to support the new mutation listener logic.

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.

1 participant