From 45de9057b6572970002288d087b97a3c21cff28f Mon Sep 17 00:00:00 2001 From: darmody Date: Tue, 9 Aug 2022 16:42:34 +0800 Subject: [PATCH] fix(editor): makes pressing Enter to send comment correctly fix #326 --- .../src/editors/commentEditor/commentEditor.tsx | 1 - .../src/editors/commentEditor/useCommentEditor.ts | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/legacy-editor/src/editors/commentEditor/commentEditor.tsx b/packages/legacy-editor/src/editors/commentEditor/commentEditor.tsx index 936fe4c87..7516224f6 100644 --- a/packages/legacy-editor/src/editors/commentEditor/commentEditor.tsx +++ b/packages/legacy-editor/src/editors/commentEditor/commentEditor.tsx @@ -24,7 +24,6 @@ export const CommentEditorContent: FC = ({ markId, onSend, m const handleSend = useCallback( (event?: MouseEvent) => { event?.stopPropagation() - console.log('editor', editor) if (!editor.current) return onSend?.(editor.current, getDraft(markId)) }, diff --git a/packages/legacy-editor/src/editors/commentEditor/useCommentEditor.ts b/packages/legacy-editor/src/editors/commentEditor/useCommentEditor.ts index 37547fa68..f15bac570 100644 --- a/packages/legacy-editor/src/editors/commentEditor/useCommentEditor.ts +++ b/packages/legacy-editor/src/editors/commentEditor/useCommentEditor.ts @@ -1,7 +1,8 @@ import { Editor, Content } from '@tiptap/core' import { useEditor } from '../../tiptapRefactor' -import { Comment } from '../../extensions' +import { Comment, CommentOptions } from '../../extensions' import { Base, BaseOptions } from '../../extensions/base' +import { useEffect } from 'react' export interface CommentEditorOptions { defaultContent?: Content @@ -14,7 +15,14 @@ export function useCommentEditor({ mentionCommands, onSendComment }: CommentEditorOptions): Editor | null { - return useEditor({ + let editor: Editor | null = null + + useEffect(() => { + const comment = editor?.extensionManager.extensions.find(extension => extension.name === Comment.name) + if (comment) (comment?.options as CommentOptions).onSendComment = onSendComment + }, [editor, onSendComment]) + + editor = useEditor({ autofocus: 'end', content: defaultContent, extensions: [ @@ -46,4 +54,6 @@ export function useCommentEditor({ }) ] }) + + return editor }