From ca45b1d00b7c365399ea444d98663567d25d3a4e Mon Sep 17 00:00:00 2001 From: Cristopher Solis Date: Fri, 13 Oct 2023 09:08:19 -0500 Subject: [PATCH] fix: fix android backspace bug (#5077) --- packages/lexical/src/LexicalEvents.ts | 5 +++++ packages/shared/src/environment.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts index 52ddd4c68a3..36c2bfed985 100644 --- a/packages/lexical/src/LexicalEvents.ts +++ b/packages/lexical/src/LexicalEvents.ts @@ -13,6 +13,7 @@ import type {TextNode} from './nodes/LexicalTextNode'; import { CAN_USE_BEFORE_INPUT, + IS_ANDROID, IS_APPLE_WEBKIT, IS_FIREFOX, IS_IOS, @@ -515,6 +516,10 @@ function onBeforeInput(event: InputEvent, editor: LexicalEditor): void { if ($isRangeSelection(selection)) { // Used for handling backspace in Android. + if (IS_ANDROID) { + $setCompositionKey(selection.anchor.key); + } + if ( isPossiblyAndroidKeyPress(event.timeStamp) && editor.isComposing() && diff --git a/packages/shared/src/environment.ts b/packages/shared/src/environment.ts index bb7761bc92c..61f1985d89f 100644 --- a/packages/shared/src/environment.ts +++ b/packages/shared/src/environment.ts @@ -40,6 +40,9 @@ export const IS_IOS: boolean = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; +export const IS_ANDROID: boolean = + CAN_USE_DOM && /Android/.test(navigator.userAgent); + // Keep these in case we need to use them in the future. // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform); export const IS_CHROME: boolean =