From db179a80860378523ff41f57b95a5adcd8d27ec2 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 24 Jan 2026 11:15:35 -0500 Subject: [PATCH] fix: Comment shortcut without selection (#11261) closes #11073 --- app/editor/index.tsx | 2 + app/scenes/Document/components/Editor.tsx | 3 ++ shared/editor/commands/comment.ts | 3 ++ shared/editor/marks/Comment.ts | 53 +++++++++++++---------- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/editor/index.tsx b/app/editor/index.tsx index 63592be4e5..82064df5e3 100644 --- a/app/editor/index.tsx +++ b/app/editor/index.tsx @@ -119,6 +119,8 @@ export type Props = { onCreateCommentMark?: (commentId: string, userId: string) => void; /** Callback when a comment mark is removed */ onDeleteCommentMark?: (commentId: string) => void; + /** Callback when comments sidebar should be opened */ + onOpenCommentsSidebar?: () => void; /** Callback when a file upload begins */ onFileUploadStart?: () => void; /** Callback when a file upload ends */ diff --git a/app/scenes/Document/components/Editor.tsx b/app/scenes/Document/components/Editor.tsx index 1d60797e35..bb55385c35 100644 --- a/app/scenes/Document/components/Editor.tsx +++ b/app/scenes/Document/components/Editor.tsx @@ -248,6 +248,9 @@ function DocumentEditor(props: Props, ref: React.RefObject) { onDeleteCommentMark={ commentingEnabled && can.comment ? handleRemoveComment : undefined } + onOpenCommentsSidebar={ + commentingEnabled ? ui.toggleComments : undefined + } onInit={handleInit} onDestroy={handleDestroy} onChange={updateDocState} diff --git a/shared/editor/commands/comment.ts b/shared/editor/commands/comment.ts index 00c67926f7..206bd29b7d 100644 --- a/shared/editor/commands/comment.ts +++ b/shared/editor/commands/comment.ts @@ -41,6 +41,9 @@ const addCommentTextSelection = if (!(state.selection instanceof TextSelection)) { return false; } + if (state.selection.empty) { + return false; + } if ( isMarkActive( diff --git a/shared/editor/marks/Comment.ts b/shared/editor/marks/Comment.ts index e78247f635..e073bde68a 100644 --- a/shared/editor/marks/Comment.ts +++ b/shared/editor/marks/Comment.ts @@ -70,30 +70,37 @@ export default class Comment extends Mark { } keys({ type }: { type: MarkType }): Record { - return this.options.onCreateCommentMark - ? { - "Mod-Alt-m": (state, dispatch) => { - if ( - isMarkActive(state.schema.marks.comment, { - resolved: false, - })(state) - ) { - return false; - } - - chainTransactions( - toggleMark(type, { - id: uuidv4(), - userId: this.options.userId, - draft: true, - }), - collapseSelection() - )(state, dispatch); - - return true; - }, + return { + "Mod-Alt-m": (state, dispatch) => { + if (state.selection.empty && this.options.onOpenCommentsSidebar) { + this.options.onOpenCommentsSidebar(); + return true; } - : {}; + + if (!this.options.onCreateCommentMark) { + return false; + } + + if ( + isMarkActive(state.schema.marks.comment, { + resolved: false, + })(state) + ) { + return false; + } + + chainTransactions( + toggleMark(type, { + id: uuidv4(), + userId: this.options.userId, + draft: true, + }), + collapseSelection() + )(state, dispatch); + + return true; + }, + }; } commands() {