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 =