sodenn / lexical-beautiful-mentions

A mentions plugin for the lexical text editor.
https://lexical-beautiful-mentions-docs.vercel.app/
MIT License
173 stars 28 forks source link

Incorrect character deletion when inserting a mention with autoSpace = false #683

Closed NatalyGraham closed 6 days ago

NatalyGraham commented 1 week ago

When the autoSpace parameter is set to false, inserting a mention right before a non-space character causes unexpected behavior. Specifically, when there is no space after the non-space characters until the end of the line, the mention deletes the characters after it.

Steps to reproduce the behavior

  1. Have text like 'some text' (without any trailing spaces).
  2. Set autoSpace to false.
  3. Attempt to insert a mention right before the word 'text' by typing the trigger character for the mention.
  4. Select a mention from the list.

Expected behavior The result should be: 'some @mentiontext' • @mention is styled as a mention. • 'text' remains regular text.

Actual Behavior The result is:

'some @mention' • The word 'text' is deleted when the mention is inserted.

Note

The behavior is correct when there is a space after 'text'. For example, if the text is 'some text ' (with a trailing space), inserting a mention before 'text' produces the correct result: 'some @mentiontext '

• @mention is styled as a mention. • 'text ' remains as regular text.

Screenshot 2024-10-17 at 16 06 20

Expected Fix

When autoSpace = false, inserting a mention right before a non-space character should not delete the non-space characters after it but should instead insert the mention inline, leaving the characters after the mention intact and styling the mention as a mention and the text as regular text.

• Version: [0.1.42] • Browser: [Chrome Version 129.0.6668.101 (Official Build) (arm64)]

dosubot[bot] commented 1 week ago

The issue you're experiencing with the lexical-beautiful-mentions plugin, where inserting a mention with autoSpace set to false deletes characters after the mention, seems to be related to how the plugin handles character retention during mention insertion. The expected behavior is that the mention should be inserted inline without deleting subsequent characters.

The current logic for handling character deletion or retention when inserting a mention involves replacing nodes and managing spaces around mentions. However, it seems that when autoSpace is set to false, the logic might not be correctly retaining the characters following the mention [1][2].

To address this, you might need to adjust the logic in the mention insertion function to ensure that characters after the mention are not removed when autoSpace is false. This would involve modifying the $insertMentionOrTrigger function to handle this specific case correctly [2].

If you have access to the code, you could look into the $insertMentionOrTrigger function in plugin/src/mention-commands.ts and adjust the logic to ensure that characters after the mention are preserved when autoSpace is false. If not, you might want to report this behavior to the maintainers for further investigation.

To continue talking to Dosu, mention @dosu.