From 18afaa1251f974ccf9fb6a2e7c16ff296cf95758 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 26 Jun 2025 15:50:43 +0200 Subject: [PATCH] Add file path and line for comments with code locations Instead of only displaying a comment, we need to make sure users know that this has been a line comment. Linking to changes for the display of the comment is a bit trickier, will do so in a follow up --- src/components/Comment.svelte | 46 +++++++++++++++++++++++++++++++++++ src/components/Thread.svelte | 1 + 2 files changed, 47 insertions(+) diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index b65395948..dcc09418c 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -3,6 +3,10 @@ import * as utils from "@app/lib/utils"; + type Side = "left" | "right"; + type SelectionAnchor = { side: Side; lineNumber: number }; + type SelectionRange = { start: SelectionAnchor; end?: SelectionAnchor }; + import Id from "@app/components/Id.svelte"; import Markdown from "@app/components/Markdown.svelte"; import NodeId from "@app/components/NodeId.svelte"; @@ -14,12 +18,28 @@ export let baseUrl: BaseUrl; export let body: string; export let reactions: Comment["reactions"] | undefined = undefined; + export let location: Comment["location"] | undefined = undefined; export let caption = "commented"; export let rawPath: string; export let timestamp: number; export let isReply: boolean = false; export let isLastReply: boolean = false; export let lastEdit: Comment["edits"][0] | undefined = undefined; + + function rangeAnchorsFromCodeLocation( + location: Comment["location"] | null, + ): SelectionRange | undefined { + if (location?.old?.type === "lines") { + return { + start: { side: "left", lineNumber: location.old.range.start }, + }; + } else if (location?.new?.type === "lines") { + return { + start: { side: "right", lineNumber: location.new.range.start }, + }; + } + } + $: selectionRange = rangeAnchorsFromCodeLocation(location);