fix: Comment shortcut without selection (#11261)

closes #11073
This commit is contained in:
Tom Moor
2026-01-24 11:15:35 -05:00
committed by GitHub
parent 6d6a42b805
commit db179a8086
4 changed files with 38 additions and 23 deletions
+2
View File
@@ -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 */
@@ -248,6 +248,9 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
onDeleteCommentMark={
commentingEnabled && can.comment ? handleRemoveComment : undefined
}
onOpenCommentsSidebar={
commentingEnabled ? ui.toggleComments : undefined
}
onInit={handleInit}
onDestroy={handleDestroy}
onChange={updateDocState}
+3
View File
@@ -41,6 +41,9 @@ const addCommentTextSelection =
if (!(state.selection instanceof TextSelection)) {
return false;
}
if (state.selection.empty) {
return false;
}
if (
isMarkActive(
+30 -23
View File
@@ -70,30 +70,37 @@ export default class Comment extends Mark {
}
keys({ type }: { type: MarkType }): Record<string, Command> {
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() {