Skip to content

Commit

Permalink
fix: input in chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
okisdev committed Jul 10, 2023
1 parent 90a8e6f commit ab0f2bc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions components/landing/main/input-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const InputArea = ({
const [filteredCommands, setFilteredCommands] = useState(CommandsList);
const [selectedCommandIndex, setSelectedCommandIndex] = useState<number>(0);

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

const enableSystemPrompt = useAtomValue(store.enableSystemPrompt);

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

const handleCompositionStart = () => {
setIsComposing(true);
};

const handleCompositionEnd = () => {
setIsComposing(false);
};

const handleOnKeyDown = (e: any) => {
if (isComposing) {
return;
}

const isShiftKey = e.shiftKey;
const isEnterKey = e.key === 'Enter';
const isEscapeKey = e.key === 'Escape';
Expand All @@ -201,9 +215,6 @@ const InputArea = ({
if (showCommands && isEnterKey) {
e.preventDefault();
handleCommandClick(`/${filteredCommands[selectedCommandIndex].name}`);
} else if (isSendOnEnter || isSendOnShiftEnter) {
e.preventDefault();
handleSend();
} else if (isEscapeKey) {
setShowCommands(false);
} else if (isUpArrow && showCommands) {
Expand All @@ -213,6 +224,11 @@ const InputArea = ({
e.preventDefault();
setSelectedCommandIndex((prevIndex) => (prevIndex < filteredCommands.length - 1 ? prevIndex + 1 : prevIndex));
}

if (isSendOnEnter || isSendOnShiftEnter) {
e.preventDefault();
handleSend();
}
};

const handleCommandClick = (command: string) => {
Expand Down Expand Up @@ -301,6 +317,8 @@ const InputArea = ({
value={userInput}
onChange={handleTextAreaChange}
onKeyDown={handleOnKeyDown}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
ref={textAreaRef}
/>
<div className='absolute bottom-2 right-2 flex items-center justify-center'>
Expand Down

1 comment on commit ab0f2bc

@vercel
Copy link

@vercel vercel bot commented on ab0f2bc Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chat-chat – ./

chat-chat-git-main-okisdev.vercel.app
chatchat-main.vercel.app
chat-chat-okisdev.vercel.app

Please sign in to comment.