From 49e6bf11e3e8783aa52cb3347c0b5a2a33591817 Mon Sep 17 00:00:00 2001 From: oonishi3 <114893022+oonishi3@users.noreply.github.com> Date: Tue, 28 Jan 2025 01:22:38 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=89=90=20fix:=20incorrect=20handling=20fo?= =?UTF-8?q?r=20composing=20CJK=20texts=20in=20Safari=20(#5496)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/hooks/Input/useTextarea.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/hooks/Input/useTextarea.ts b/client/src/hooks/Input/useTextarea.ts index 3a74a5ac5e9..ab881d7417a 100644 --- a/client/src/hooks/Input/useTextarea.ts +++ b/client/src/hooks/Input/useTextarea.ts @@ -191,6 +191,9 @@ export default function useTextarea({ const isNonShiftEnter = e.key === 'Enter' && !e.shiftKey; const isCtrlEnter = e.key === 'Enter' && (e.ctrlKey || e.metaKey); + // NOTE: isComposing and e.key behave differently in Safari compared to other browsers, forcing us to use e.keyCode instead + const isComposingInput = isComposing.current || e.key === 'Process' || e.keyCode === 229; + if (isNonShiftEnter && filesLoading) { e.preventDefault(); } @@ -204,7 +207,7 @@ export default function useTextarea({ !enterToSend && !isCtrlEnter && textAreaRef.current && - !isComposing.current + !isComposingInput ) { e.preventDefault(); insertTextAtCursor(textAreaRef.current, '\n'); @@ -212,7 +215,7 @@ export default function useTextarea({ return; } - if ((isNonShiftEnter || isCtrlEnter) && !isComposing.current) { + if ((isNonShiftEnter || isCtrlEnter) && !isComposingInput) { const globalAudio = document.getElementById(globalAudioId) as HTMLAudioElement | undefined; if (globalAudio) { console.log('Unmuting global audio');