diff --git a/packages/editor/src/core/extensions/enter-key-extension.tsx b/packages/editor/src/core/extensions/enter-key-extension.tsx index 311ead4976..d67ceb78b8 100644 --- a/packages/editor/src/core/extensions/enter-key-extension.tsx +++ b/packages/editor/src/core/extensions/enter-key-extension.tsx @@ -1,6 +1,6 @@ import { Extension } from "@tiptap/core"; -export const EnterKeyExtension = (onEnterKeyPress?: (descriptionHTML: string) => void) => +export const EnterKeyExtension = (onEnterKeyPress?: () => void) => Extension.create({ name: "enterKey", @@ -8,7 +8,9 @@ export const EnterKeyExtension = (onEnterKeyPress?: (descriptionHTML: string) => return { Enter: () => { if (!this.editor.storage.mentionsOpen) { - onEnterKeyPress?.(this.editor.getHTML()); + if (onEnterKeyPress) { + onEnterKeyPress(); + } return true; } return false; diff --git a/packages/editor/src/core/types/editor.ts b/packages/editor/src/core/types/editor.ts index f817969c3e..25a37f0ca3 100644 --- a/packages/editor/src/core/types/editor.ts +++ b/packages/editor/src/core/types/editor.ts @@ -35,7 +35,7 @@ export interface IEditorProps { suggestions?: () => Promise; }; onChange?: (json: object, html: string) => void; - onEnterKeyPress?: (descriptionHTML: string) => void; + onEnterKeyPress?: (e?: any) => void; placeholder?: string | ((isFocused: boolean, value: string) => string); tabIndex?: number; value?: string | null; diff --git a/space/core/components/editor/lite-text-editor.tsx b/space/core/components/editor/lite-text-editor.tsx index 698a6695c1..3cc8347a17 100644 --- a/space/core/components/editor/lite-text-editor.tsx +++ b/space/core/components/editor/lite-text-editor.tsx @@ -64,11 +64,7 @@ export const LiteTextEditor = React.forwardRef { - if (isMutableRefObject(ref)) { - rest.onEnterKeyPress?.(ref.current?.getHTML() ?? ""); - } - }} + handleSubmit={(e) => rest.onEnterKeyPress?.(e)} isCommentEmpty={isEmpty} editorRef={isMutableRefObject(ref) ? ref : null} /> diff --git a/space/core/components/editor/toolbar.tsx b/space/core/components/editor/toolbar.tsx index a16cd0e203..3b0942e17a 100644 --- a/space/core/components/editor/toolbar.tsx +++ b/space/core/components/editor/toolbar.tsx @@ -12,7 +12,7 @@ import { cn } from "@/helpers/common.helper"; type Props = { executeCommand: (commandKey: TEditorCommands) => void; - handleSubmit: () => void; + handleSubmit: (event: React.MouseEvent) => void; isCommentEmpty: boolean; isSubmitting: boolean; showSubmitButton: boolean; diff --git a/space/core/components/issues/peek-overview/comment/add-comment.tsx b/space/core/components/issues/peek-overview/comment/add-comment.tsx index a602538e00..29b1519f5e 100644 --- a/space/core/components/issues/peek-overview/comment/add-comment.tsx +++ b/space/core/components/issues/peek-overview/comment/add-comment.tsx @@ -66,8 +66,8 @@ export const AddComment: React.FC = observer((props) => { control={control} render={({ field: { value, onChange } }) => ( { - if (currentUser) handleSubmit(onSubmit)(); + onEnterKeyPress={(e) => { + if (currentUser) handleSubmit(onSubmit)(e); }} workspaceId={workspaceID?.toString() ?? ""} workspaceSlug={workspaceSlug?.toString() ?? ""} diff --git a/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx b/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx index 67738b524d..47b506b965 100644 --- a/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx +++ b/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx @@ -103,7 +103,7 @@ export const CommentCard: React.FC = observer((props) => { handleSubmit(handleCommentUpdate)()} + onEnterKeyPress={handleSubmit(handleCommentUpdate)} ref={editorRef} id={comment.id} initialValue={value} diff --git a/web/core/components/editor/lite-text-editor/lite-text-editor.tsx b/web/core/components/editor/lite-text-editor/lite-text-editor.tsx index 447f4f309e..4ded0e84c9 100644 --- a/web/core/components/editor/lite-text-editor/lite-text-editor.tsx +++ b/web/core/components/editor/lite-text-editor/lite-text-editor.tsx @@ -94,11 +94,7 @@ export const LiteTextEditor = React.forwardRef { - if (isMutableRefObject(ref)) { - rest.onEnterKeyPress?.(ref.current?.getHTML() ?? ""); - } - }} + handleSubmit={(e) => rest.onEnterKeyPress?.(e)} isCommentEmpty={isEmpty} isSubmitting={isSubmitting} showAccessSpecifier={showAccessSpecifier} diff --git a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx index 0ea9e8f15b..798964365e 100644 --- a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx +++ b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx @@ -137,7 +137,11 @@ export const IssueCommentCard: FC = observer((props) => { > <>
-
+
{ + if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && !isEmpty) handleSubmit(onEnter)(e); + }} + > = observer((props) => { initialValue={watch("comment_html") ?? ""} value={null} onChange={(comment_json, comment_html) => setValue("comment_html", comment_html)} - onEnterKeyPress={(commentHTML) => { - const isCommentEmpty = - commentHTML?.trim() === "" || - commentHTML === "

" || - (isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component")); - if (!isCommentEmpty && !isSubmitting) { - handleSubmit(onEnter)(); + onEnterKeyPress={(e) => { + if (!isEmpty && !isSubmitting) { + handleSubmit(onEnter)(e); } }} showSubmitButton={false} diff --git a/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx b/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx index 90df745b39..9040ab268b 100644 --- a/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx +++ b/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx @@ -33,6 +33,7 @@ export const IssueCommentCreate: FC = (props) => { const { handleSubmit, control, + watch, formState: { isSubmitting }, reset, } = useForm>({ @@ -49,8 +50,19 @@ export const IssueCommentCreate: FC = (props) => { editorRef.current?.clearEditor(); }); + const commentHTML = watch("comment_html"); + const isEmpty = + commentHTML?.trim() === "" || + commentHTML === "

" || + (isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component")); + return ( -
+
{ + if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && !isEmpty && !isSubmitting) + handleSubmit(onSubmit)(e); + }} + > = (props) => { value={"

"} projectId={projectId} workspaceSlug={workspaceSlug} - onEnterKeyPress={(commentHTML) => { - const isEmpty = - commentHTML?.trim() === "" || - commentHTML === "

" || - (isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component")); + onEnterKeyPress={(e) => { if (!isEmpty && !isSubmitting) { - handleSubmit(onSubmit)(); + handleSubmit(onSubmit)(e); } }} ref={editorRef}