Skip to content

Commit

Permalink
Fix chat_input enter submission for Chinese and Japanse (streamlit#…
Browse files Browse the repository at this point in the history
…6993)

* ignore Enter on composition for Japanese

* fix incorrect indent num

* write comment why uncapture Enter with isComposing

* case of the lack of no nativeEvent or isComposing

for test sets widget value when ⌘+enter
  • Loading branch information
chakku000 authored and Your Name committed Mar 22, 2024
1 parent 398b2ee commit 04c9e37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion frontend/lib/src/components/widgets/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ const isEnterKeyPressed = (
// https://bugs.chromium.org/p/chromium/issues/detail?id=79407

const { keyCode, key } = event
return key === "Enter" || keyCode === 13 || keyCode === 10
return (
(key === "Enter" || keyCode === 13 || keyCode === 10) &&
// Do not send the sentence being composed when Enter is typed into the IME.
!(event.nativeEvent?.isComposing === true)
)
}

function ChatInput({ width, element, widgetMgr }: Props): React.ReactElement {
Expand Down
6 changes: 5 additions & 1 deletion frontend/lib/src/components/widgets/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ class TextArea extends React.PureComponent<Props, State> {

// Using keyCode as well due to some different behaviors on Windows
// https://bugs.chromium.org/p/chromium/issues/detail?id=79407
return key === "Enter" || keyCode === 13 || keyCode === 10
return (
(key === "Enter" || keyCode === 13 || keyCode === 10) &&
// Do not send the sentence being composed when Enter is typed into the IME.
!(event.nativeEvent?.isComposing === true)
)
}

private onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>): void => {
Expand Down

0 comments on commit 04c9e37

Please sign in to comment.