mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 22:29:26 +00:00
feat(ui): auto-focus chat input when reply is clicked
This commit is contained in:
@@ -140,6 +140,20 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
}
|
||||
}, [initialText])
|
||||
|
||||
// Focus editor when replyingTo becomes truthy
|
||||
useEffect(() => {
|
||||
if (replyingTo && editorRef.current) {
|
||||
editorRef.current.focus()
|
||||
// Focus and move cursor to end
|
||||
const range = document.createRange()
|
||||
const sel = window.getSelection()
|
||||
range.selectNodeContents(editorRef.current)
|
||||
range.collapse(false)
|
||||
sel?.removeAllRanges()
|
||||
sel?.addRange(range)
|
||||
}
|
||||
}, [replyingTo])
|
||||
|
||||
// Clean up drawing mode on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user