From 539e9885ed8b63cc8ec8ce244006351266ede872 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 5 Nov 2021 21:56:43 +0300 Subject: [PATCH] Composer: Fix jumping cursor when entering emoji (#1527) --- src/components/middle/composer/MessageInput.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx index 649694b4c..d40f53c58 100644 --- a/src/components/middle/composer/MessageInput.tsx +++ b/src/components/middle/composer/MessageInput.tsx @@ -14,7 +14,7 @@ import focusEditableElement from '../../../util/focusEditableElement'; import buildClassName from '../../../util/buildClassName'; import { pick } from '../../../util/iteratees'; import { - IS_ANDROID, IS_IOS, IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV, + IS_ANDROID, IS_EMOJI_SUPPORTED, IS_IOS, IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV, } from '../../../util/environment'; import captureKeyboardListeners from '../../../util/captureKeyboardListeners'; import useLayoutEffectWithPrevDeps from '../../../hooks/useLayoutEffectWithPrevDeps'; @@ -279,7 +279,12 @@ const MessageInput: FC = ({ onUpdate(innerHTML === SAFARI_BR ? '' : innerHTML); // Reset focus on the input to remove any active styling when input is cleared - if (!IS_TOUCH_ENV && (!textContent || !textContent.length)) { + if ( + !IS_TOUCH_ENV + && (!textContent || !textContent.length) + // When emojis are not supported, innerHTML contains an emoji img tag that doesn't exist in the textContext + && !(!IS_EMOJI_SUPPORTED && innerHTML.includes('emoji-small')) + ) { const selection = window.getSelection()!; if (selection) { inputRef.current!.blur();