From 83bae9e9d9e1571b341178a0fb12bee0a17baaec Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Thu, 9 May 2024 19:31:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20android=20keyboard=20`@`?= =?UTF-8?q?=20popover=20issue=20(#2647)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/hooks/Input/useTextarea.ts | 44 ++++++++------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/client/src/hooks/Input/useTextarea.ts b/client/src/hooks/Input/useTextarea.ts index 1da901418b..8c39e76dde 100644 --- a/client/src/hooks/Input/useTextarea.ts +++ b/client/src/hooks/Input/useTextarea.ts @@ -14,11 +14,6 @@ import store from '~/store'; type KeyEvent = KeyboardEvent; -const keyMap = { - 50: '2', - 192: '@', -}; - export default function useTextarea({ textAreaRef, submitButtonRef, @@ -141,35 +136,22 @@ export default function useTextarea({ assistantMap, ]); - const handleKeyUp = useCallback( - (e: KeyEvent) => { - let normalizedKey = e.key; + const handleKeyUp = useCallback(() => { + const text = textAreaRef.current?.value; + if (!(text && text[text.length - 1] === '@')) { + return; + } - if (!normalizedKey || normalizedKey === 'Unidentified') { - normalizedKey = keyMap[e.keyCode] || normalizedKey; - } + const startPos = textAreaRef.current?.selectionStart; + if (!startPos) { + return; + } - if (normalizedKey !== '@' && normalizedKey !== '2') { - return; - } + const isAtStart = startPos === 1; + const isPrecededBySpace = textAreaRef.current?.value.charAt(startPos - 2) === ' '; - const text = textAreaRef.current?.value; - if (!(text && text[text.length - 1] === '@')) { - return; - } - - const startPos = textAreaRef.current?.selectionStart; - if (!startPos) { - return; - } - - const isAtStart = startPos === 1; - const isPrecededBySpace = textAreaRef.current?.value.charAt(startPos - 2) === ' '; - - setShowMentionPopover(isAtStart || isPrecededBySpace); - }, - [textAreaRef, setShowMentionPopover], - ); + setShowMentionPopover(isAtStart || isPrecededBySpace); + }, [textAreaRef, setShowMentionPopover]); const handleKeyDown = useCallback( (e: KeyEvent) => {