🔧 fix: android keyboard @ popover issue (#2647)

This commit is contained in:
Marco Beretta 2024-05-09 19:31:55 +02:00 committed by GitHub
parent 6ba7f60eec
commit 83bae9e9d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,11 +14,6 @@ import store from '~/store';
type KeyEvent = KeyboardEvent<HTMLTextAreaElement>; type KeyEvent = KeyboardEvent<HTMLTextAreaElement>;
const keyMap = {
50: '2',
192: '@',
};
export default function useTextarea({ export default function useTextarea({
textAreaRef, textAreaRef,
submitButtonRef, submitButtonRef,
@ -141,35 +136,22 @@ export default function useTextarea({
assistantMap, assistantMap,
]); ]);
const handleKeyUp = useCallback( const handleKeyUp = useCallback(() => {
(e: KeyEvent) => { const text = textAreaRef.current?.value;
let normalizedKey = e.key; if (!(text && text[text.length - 1] === '@')) {
return;
}
if (!normalizedKey || normalizedKey === 'Unidentified') { const startPos = textAreaRef.current?.selectionStart;
normalizedKey = keyMap[e.keyCode] || normalizedKey; if (!startPos) {
} return;
}
if (normalizedKey !== '@' && normalizedKey !== '2') { const isAtStart = startPos === 1;
return; const isPrecededBySpace = textAreaRef.current?.value.charAt(startPos - 2) === ' ';
}
const text = textAreaRef.current?.value; setShowMentionPopover(isAtStart || isPrecededBySpace);
if (!(text && text[text.length - 1] === '@')) { }, [textAreaRef, setShowMentionPopover]);
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],
);
const handleKeyDown = useCallback( const handleKeyDown = useCallback(
(e: KeyEvent) => { (e: KeyEvent) => {