Bug: Android GBoard - BACKSPACE bug when deleting a mention (playground)
Lexical version: v0.12.5
Steps To Reproduce
- On Android, goto https://playground.lexical.dev/
- Type @ and mention someone
- Hit BACKSPACE to delete the just-added mention
Link to code example: lexical playground
The current behavior
- Last character won't be deleted, then the other characters are deleted one by one (see recording)
https://github.com/facebook/lexical/assets/1011106/0c02eb95-fe72-408c-a44e-754fb9915b27
The expected behavior
- Mention (as segmented TextNode) should be deleted word by word
https://github.com/facebook/lexical/assets/1011106/54ac9ef7-2278-4a2c-9078-075b326ec4d8
This issue seems only happen with GBoard
how to resolve it?
The issue comes from #5644, which fixes other bugs but causes this one.
I managed to fix it temporarily by ignoring mention nodes. On packages/lexical/src/LexicalEvents.ts:
const shouldLetBrowserHandleDelete =
IS_ANDROID_CHROME &&
isSelectionAnchorSameAsFocus &&
!hasSelectedAllTextInNode &&
selection.anchor.getNode().__type !== 'mention'; // use the type of the node you need
I got the type of the mentions node from here.
I'm not sure why the bug happens; #5644 delegates to the browser the handling of deletions on some cases, so I suppose MentionNode must be deleted through Lexical's dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);.