Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
fix(editor): makes pressing Enter to send comment correctly
Browse files Browse the repository at this point in the history
fix #326
  • Loading branch information
Darmody committed Aug 9, 2022
1 parent 2a87b8a commit 45de905
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const CommentEditorContent: FC<CommentEditorProps> = ({ markId, onSend, m
const handleSend = useCallback(
(event?: MouseEvent) => {
event?.stopPropagation()
console.log('editor', editor)
if (!editor.current) return
onSend?.(editor.current, getDraft(markId))
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: [
Expand Down Expand Up @@ -46,4 +54,6 @@ export function useCommentEditor({
})
]
})

return editor
}

0 comments on commit 45de905

Please sign in to comment.