From 39ac609d479aad898b083fcbc72911619b10d274 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Mon, 18 May 2026 10:35:44 +1000 Subject: [PATCH] fix(diff-viewer): reset comment editor scroll on comment change The CommentEditor textarea reused its scrollTop across comments, so switching from a long, scrolled comment to another comment kept the old offset and hid the new comment's top. Bind the textarea and reset scrollTop in the effect that swaps in the new content. Signed-off-by: Matt Toohey --- .../diff-viewer/src/lib/components/CommentEditor.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/diff-viewer/src/lib/components/CommentEditor.svelte b/packages/diff-viewer/src/lib/components/CommentEditor.svelte index 1a53cd464..316f5f379 100644 --- a/packages/diff-viewer/src/lib/components/CommentEditor.svelte +++ b/packages/diff-viewer/src/lib/components/CommentEditor.svelte @@ -58,10 +58,15 @@ // Track current input value - initialized by effect when existingComment changes let currentValue = $state(''); + let textareaEl: HTMLTextAreaElement | null = null; - // Update value when existingComment changes (for editing mode) + // Update value when existingComment changes (for editing mode). Reset scroll + // on identity change so a previously-scrolled textarea doesn't leak its + // offset into the next comment being viewed. $effect(() => { + existingComment?.id; currentValue = existingComment?.content ?? ''; + if (textareaEl) textareaEl.scrollTop = 0; }); function handleInput(e: Event) { @@ -107,6 +112,7 @@ style="top: {top}px; left: {left}px; width: {width}px;" >