Skip to content

Commit

Permalink
Merge pull request Stability-AI#4 from PeterTakahashi/fix/support-jap…
Browse files Browse the repository at this point in the history
…anese-typing

fix: support japanese typing
  • Loading branch information
mckaywrigley authored Mar 18, 2023
2 parents 7f35469 + 3ba74d9 commit 506b5c1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Props {

export const ChatInput: FC<Props> = ({ onSend }) => {
const [content, setContent] = useState<string>();
const [isTyping, setIsTyping] = useState<boolean>(false);

const textareaRef = useRef<HTMLTextAreaElement>(null);

Expand All @@ -31,7 +32,7 @@ export const ChatInput: FC<Props> = ({ onSend }) => {
};

const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
if (!isTyping && e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
handleSend();
}
Expand All @@ -54,6 +55,8 @@ export const ChatInput: FC<Props> = ({ onSend }) => {
placeholder="Type a message..."
value={content}
rows={1}
onCompositionStart={() => setIsTyping(true)}
onCompositionEnd={() => setIsTyping(false)}
onChange={handleChange}
onKeyDown={handleKeyDown}
/>
Expand Down

0 comments on commit 506b5c1

Please sign in to comment.