lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Android GBoard - BACKSPACE bug when deleting a mention (playground)

Open bnol opened this issue 2 years ago • 3 comments

Lexical version: v0.12.5

Steps To Reproduce

  1. On Android, goto https://playground.lexical.dev/
  2. Type @ and mention someone
  3. 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

bnol avatar Dec 11 '23 02:12 bnol

This issue seems only happen with GBoard

bnol avatar Dec 13 '23 03:12 bnol

how to resolve it?

Vellaiyan-Marimuthu avatar Feb 29 '24 16:02 Vellaiyan-Marimuthu

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);.

dani-lp avatar Apr 24 '24 18:04 dani-lp