Skip to content

Commit ab0f2bc

Browse files
committed
fix: input in chinese
1 parent 90a8e6f commit ab0f2bc

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

components/landing/main/input-area.tsx

+21-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ const InputArea = ({
4545
const [filteredCommands, setFilteredCommands] = useState(CommandsList);
4646
const [selectedCommandIndex, setSelectedCommandIndex] = useState<number>(0);
4747

48+
// Keyboard
4849
const isSendKeyEnter = useAtomValue(store.isSendKeyEnterAtom);
50+
const [isComposing, setIsComposing] = useState<boolean>(false);
4951

5052
const enableSystemPrompt = useAtomValue(store.enableSystemPrompt);
5153

@@ -188,7 +190,19 @@ const InputArea = ({
188190
toast.success(`${t('Copied share link:')} ${conversationID}`);
189191
};
190192

193+
const handleCompositionStart = () => {
194+
setIsComposing(true);
195+
};
196+
197+
const handleCompositionEnd = () => {
198+
setIsComposing(false);
199+
};
200+
191201
const handleOnKeyDown = (e: any) => {
202+
if (isComposing) {
203+
return;
204+
}
205+
192206
const isShiftKey = e.shiftKey;
193207
const isEnterKey = e.key === 'Enter';
194208
const isEscapeKey = e.key === 'Escape';
@@ -201,9 +215,6 @@ const InputArea = ({
201215
if (showCommands && isEnterKey) {
202216
e.preventDefault();
203217
handleCommandClick(`/${filteredCommands[selectedCommandIndex].name}`);
204-
} else if (isSendOnEnter || isSendOnShiftEnter) {
205-
e.preventDefault();
206-
handleSend();
207218
} else if (isEscapeKey) {
208219
setShowCommands(false);
209220
} else if (isUpArrow && showCommands) {
@@ -213,6 +224,11 @@ const InputArea = ({
213224
e.preventDefault();
214225
setSelectedCommandIndex((prevIndex) => (prevIndex < filteredCommands.length - 1 ? prevIndex + 1 : prevIndex));
215226
}
227+
228+
if (isSendOnEnter || isSendOnShiftEnter) {
229+
e.preventDefault();
230+
handleSend();
231+
}
216232
};
217233

218234
const handleCommandClick = (command: string) => {
@@ -301,6 +317,8 @@ const InputArea = ({
301317
value={userInput}
302318
onChange={handleTextAreaChange}
303319
onKeyDown={handleOnKeyDown}
320+
onCompositionStart={handleCompositionStart}
321+
onCompositionEnd={handleCompositionEnd}
304322
ref={textAreaRef}
305323
/>
306324
<div className='absolute bottom-2 right-2 flex items-center justify-center'>

0 commit comments

Comments
 (0)