Skip to content

Commit

Permalink
🉐 fix: incorrect handling for composing CJK texts in Safari (#5496)
Browse files Browse the repository at this point in the history
  • Loading branch information
oonishi3 authored Jan 27, 2025
1 parent 5f8fade commit 47b72e8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/src/hooks/Input/useTextarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -204,15 +207,15 @@ export default function useTextarea({
!enterToSend &&
!isCtrlEnter &&
textAreaRef.current &&
!isComposing.current
!isComposingInput
) {
e.preventDefault();
insertTextAtCursor(textAreaRef.current, '\n');
forceResize(textAreaRef.current);
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');
Expand Down

0 comments on commit 47b72e8

Please sign in to comment.