fix(comment): 修复评论框提交后重置和聚焦的问题

1. 为CommentEditor的focus方法添加preventScroll可选参数并透传调用
2. 使用ref记录上次提交计数,避免首次挂载时重复清空输入框
3. 仅在submitCount实际变化时重置表单并聚焦编辑器
This commit is contained in:
2026-08-08 15:09:43 +08:00
parent 536707f812
commit 4f42a2faff
2 changed files with 6 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ import type { Sticker } from '../data/stickers';
export interface CommentEditorHandle {
getHTML: () => string;
isEmpty: () => boolean;
focus: () => void;
focus: (options?: { preventScroll?: boolean }) => void;
}
interface Props {
@@ -160,7 +160,7 @@ const CommentEditor = forwardRef<CommentEditorHandle, Props>(function CommentEdi
useImperativeHandle(ref, () => ({
getHTML: () => editor ? sanitizeHtml(editor.getHTML()) : value,
isEmpty: () => editor ? isEditorEmpty(editor) : !value.trim(),
focus: () => { editor?.commands.focus(); },
focus: (options?: { preventScroll?: boolean }) => { editor?.commands.focus(options); },
}), [editor, value]);
const insertSticker = useCallback((sticker: Sticker) => {