Files
kandev/apps/web/lib/markdown/preview-comments.ts
T
2026-09-18 16:03:18 +01:00

40 lines
1.3 KiB
TypeScript

import type { DiffComment } from "@/lib/state/slices/comments";
import { buildDiffComment } from "@/lib/diff/comment-utils";
import type { SourceLineRange } from "./source-line-ranges";
export type BuildMarkdownPreviewCommentArgs = SourceLineRange & {
filePath: string;
repositoryId?: string;
repositoryName?: string;
sessionId: string;
selectedText: string;
text: string;
};
export function buildMarkdownPreviewComment(args: BuildMarkdownPreviewCommentArgs): DiffComment {
const comment = buildDiffComment({
filePath: args.filePath,
repositoryName: args.repositoryName ?? "",
sessionId: args.sessionId,
startLine: args.startLine,
endLine: args.endLine,
side: "additions",
text: args.text,
codeContent: args.selectedText,
});
if (args.repositoryId) comment.repositoryId = args.repositoryId;
return comment;
}
export function commentsOverlapRange(comments: DiffComment[], range: SourceLineRange): boolean {
return comments.some(
(comment) => comment.startLine <= range.endLine && comment.endLine >= range.startLine,
);
}
export function commentsBeginInRange(comments: DiffComment[], range: SourceLineRange): boolean {
return comments.some(
(comment) => comment.startLine >= range.startLine && comment.startLine <= range.endLine,
);
}