Skip to content

Commit

Permalink
[#62287] Allow merging comments via drag & drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin authored and mgielda committed Jul 30, 2024
1 parent b93d61d commit 3d333c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/comments/sidebarWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CommentMarker extends GutterMarker {

if (this.lineNumber) {
this.gutterMarker.style.width = this.lineNumber.toString().length * 7 + "px";
this.gutterMarker.ondrop = () => this.ycomments.positions().move(this.ycomments.draggedComment, this.lineNumber);
this.gutterMarker.ondrop = () => this.ycomments.moveOrMerge(this.ycomments.draggedComment, this.lineNumber);
this.gutterMarker.ondragover = (e) => e.preventDefault();
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/comments/ycomments.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,17 @@ export class YComments {
this.display().setVisibility(id, true);
}
}

moveOrMerge(commentId, targetLine) {
if (!this.positions().isOccupied(targetLine)) {
this.positions().move(commentId, targetLine);
} else {
const id = this.findCommentOn(targetLine).commentId;
this.lineAuthors(id).appendFrom(this.lineAuthors(commentId).lineAuthors);
const text = this.getTextForComment(id);
text.insert(text.length, "\n" + this.getTextForComment(commentId).toString());
this.deleteComment(commentId);
this.display().setVisibility(id, true);
}
}
}
5 changes: 4 additions & 1 deletion src/components/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ const YComment = ({ ycomments, commentId, collaboration }) => {

const lineAuthors = useMemo(() => ycomments.lineAuthors(commentId), [commentId]);

const updateHeight = useCallback((update) => update.heightChanged && ycomments.updateHeight(commentId, cmref.current.clientHeight), [commentId]);
const updateHeight = useCallback(
(update) => update.heightChanged && update.view.requestMeasure({ read: (view) => ycomments.updateHeight(commentId, view.dom.clientHeight) }),
[commentId],
);

const parentHeight = ycomments.parentLineHeight(commentId) + 3.8;

Expand Down

0 comments on commit 3d333c0

Please sign in to comment.