fix: message editor doesn't resize (#6924)

* fix: message editor doesn't resize

* fix: remove console log

* fix: optimize useEffect dependencies and improve textarea resizing logic

---------

Co-authored-by: Pleasurecruise <3196812536@qq.com>
This commit is contained in:
Wang Jiyuan 2025-06-06 22:02:48 +08:00 committed by GitHub
parent dc21dd1802
commit f033a73187
2 changed files with 11 additions and 24 deletions

View File

@ -45,16 +45,6 @@ const MessageBlockEditor: FC<Props> = ({ message, onSave, onResend, onCancel })
const textareaRef = useRef<TextAreaRef>(null)
const attachmentButtonRef = useRef<AttachmentButtonRef>(null)
useEffect(() => {
setTimeout(() => {
resizeTextArea()
if (textareaRef.current) {
textareaRef.current.focus({ cursor: 'end' })
}
}, 0)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const resizeTextArea = useCallback(() => {
const textArea = textareaRef.current?.resizableTextArea?.textArea
if (textArea) {
@ -63,6 +53,15 @@ const MessageBlockEditor: FC<Props> = ({ message, onSave, onResend, onCancel })
}
}, [])
useEffect(() => {
setTimeout(() => {
resizeTextArea()
if (textareaRef.current) {
textareaRef.current.focus({ cursor: 'end' })
}
}, 0)
}, [resizeTextArea])
const onPaste = useCallback(
async (event: ClipboardEvent) => {
return await PasteService.handlePaste(
@ -84,13 +83,9 @@ const MessageBlockEditor: FC<Props> = ({ message, onSave, onResend, onCancel })
// 添加全局粘贴事件处理
useEffect(() => {
// 注册当前组件的粘贴处理函数
PasteService.registerHandler('messageEditor', onPaste)
// 在组件加载时将焦点设置为当前组件
PasteService.setLastFocusedComponent('messageEditor')
// 卸载时取消注册
return () => {
PasteService.unregisterHandler('messageEditor')
}
@ -165,12 +160,6 @@ const MessageBlockEditor: FC<Props> = ({ message, onSave, onResend, onCancel })
}
}
const autoResizeTextArea = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const textarea = e.target
textarea.style.height = 'auto'
textarea.style.height = `${textarea.scrollHeight}px`
}
return (
<EditorContainer className="message-editor" onDragOver={(e) => e.preventDefault()} onDrop={handleDrop}>
{editedBlocks
@ -184,7 +173,7 @@ const MessageBlockEditor: FC<Props> = ({ message, onSave, onResend, onCancel })
value={block.content}
onChange={(e) => {
handleTextChange(block.id, e.target.value)
autoResizeTextArea(e)
resizeTextArea()
}}
autoFocus
contextMenu="true"

View File

@ -101,11 +101,9 @@ const AboutSettings: FC = () => {
setVersion(appInfo.version)
setIsPortable(appInfo.isPortable)
})
// 初始化设置
setEarlyAccess(earlyAccess)
setAutoCheckUpdate(autoCheckUpdate)
}, [])
}, [autoCheckUpdate, earlyAccess, setAutoCheckUpdate, setEarlyAccess])
return (
<SettingContainer theme={theme}>