Skip to content

Commit

Permalink
fix: simplify Enter key handling and remove unused ref (langgenius#10413
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SuzukiKatsuma authored and JunXu01 committed Nov 9, 2024
1 parent 101296b commit 66d6bbe
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions web/app/components/base/chat/chat/chat-input-area/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
useCallback,
useRef,
useState,
} from 'react'
import Textarea from 'rc-textarea'
Expand Down Expand Up @@ -63,7 +62,6 @@ const ChatInputArea = ({
isMultipleLine,
} = useTextAreaHeight()
const [query, setQuery] = useState('')
const isUseInputMethod = useRef(false)
const [showVoiceInput, setShowVoiceInput] = useState(false)
const filesStore = useFileStore()
const {
Expand Down Expand Up @@ -95,20 +93,11 @@ const ChatInputArea = ({
}
}

const handleKeyUp = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter') {
e.preventDefault()
// prevent send message when using input method enter
if (!e.shiftKey && !isUseInputMethod.current)
handleSend()
}
}

const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
isUseInputMethod.current = e.nativeEvent.isComposing
if (e.key === 'Enter' && !e.shiftKey) {
setQuery(query.replace(/\n$/, ''))
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault()
setQuery(query.replace(/\n$/, ''))
handleSend()
}
}

Expand Down Expand Up @@ -165,7 +154,6 @@ const ChatInputArea = ({
setQuery(e.target.value)
handleTextareaResize()
}}
onKeyUp={handleKeyUp}
onKeyDown={handleKeyDown}
onPaste={handleClipboardPasteFile}
onDragEnter={handleDragFileEnter}
Expand Down

0 comments on commit 66d6bbe

Please sign in to comment.