From 23052dbcdae845273ef6551c97fe0282fde3de02 Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Mon, 19 Oct 2026 20:05:06 -0400 Subject: [PATCH] web: keep half-written review comments, and soften the diff's line colours A draft's text lived only in its card, so the review counted it as empty and dropped it when another comment was started. The text now lives on the comment as it is typed, and only drafts nobody typed into give way. Added and removed lines were tinted at Pierre's strength, which shouted over the code. They now mix a little of the theme's added and removed colours into the canvas ground, a little more for the changed words. --- web/src/lib/review.svelte.ts | 12 ++++++++++-- web/src/lib/views/CommentNote.svelte | 10 +++++----- web/src/lib/views/DiffView.svelte | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/web/src/lib/review.svelte.ts b/web/src/lib/review.svelte.ts index 71538a424..9600728ab 100644 --- a/web/src/lib/review.svelte.ts +++ b/web/src/lib/review.svelte.ts @@ -17,6 +17,8 @@ export interface Comment { text: string; /** Still being written; not part of the review until added. */ draft: boolean; + /** What the open field holds, kept here so it survives the card redrawing. */ + typed: string; } /** What a diff's anchor carries: the comment it stands for. */ @@ -46,7 +48,13 @@ export class Review { start(path: string, change: number, range: SelectedLineRange) { const side = range.endSide ?? range.side ?? 'additions'; const [start, end] = range.start <= range.end ? [range.start, range.end] : [range.end, range.start]; - this.comments = [...this.comments.filter((comment) => !(comment.draft && !comment.text.trim())), { id: uuidv7(), path, change, side, start, end, text: '', draft: true }]; + // A draft someone typed into stays open; only empty ones give way. + const kept = this.comments.filter((comment) => !(comment.draft && !comment.typed.trim() && !comment.text)); + this.comments = [...kept, { id: uuidv7(), path, change, side, start, end, text: '', draft: true, typed: '' }]; + } + + type(id: string, typed: string) { + this.comments = this.comments.map((comment) => (comment.id === id ? { ...comment, typed } : comment)); } save(id: string, text: string) { @@ -55,7 +63,7 @@ export class Review { } edit(id: string) { - this.comments = this.comments.map((comment) => (comment.id === id ? { ...comment, draft: true } : comment)); + this.comments = this.comments.map((comment) => (comment.id === id ? { ...comment, draft: true, typed: comment.text } : comment)); } remove(id: string) { diff --git a/web/src/lib/views/CommentNote.svelte b/web/src/lib/views/CommentNote.svelte index 7b4333250..4540cd155 100644 --- a/web/src/lib/views/CommentNote.svelte +++ b/web/src/lib/views/CommentNote.svelte @@ -4,12 +4,12 @@ // One comment beside the lines it is about: a field while it is written, // then its text with edit and remove. let { comment, review }: { comment: Comment; review: Review } = $props(); - // svelte-ignore state_referenced_locally - let text = $state(comment.text); + const text = $derived(comment.typed); let field = $state(); + // Focus a field when it opens, not on every keystroke elsewhere. $effect(() => { - if (comment.draft) field?.focus(); + if (field) field.focus(); }); const quick = ['explain this', 'why this way?', 'change this:']; @@ -24,10 +24,10 @@
{comment.start === comment.end ? `line ${comment.start}` : `lines ${comment.start}–${comment.end}`}{comment.side === 'deletions' ? ' (removed)' : ''} {#if comment.draft} - +
{#each quick as phrase (phrase)} - + {/each} diff --git a/web/src/lib/views/DiffView.svelte b/web/src/lib/views/DiffView.svelte index 4317ff36b..306783231 100644 --- a/web/src/lib/views/DiffView.svelte +++ b/web/src/lib/views/DiffView.svelte @@ -56,6 +56,12 @@ --diffs-addition-color-override: var(--added); --diffs-deletion-color-override: var(--danger); --diffs-selection-color-override: var(--accent); + --diffs-bg-addition-override: color-mix(in oklab, var(--added) 8%, var(--well)); + --diffs-bg-addition-number-override: color-mix(in oklab, var(--added) 12%, var(--well)); + --diffs-bg-addition-emphasis-override: color-mix(in oklab, var(--added) 20%, var(--well)); + --diffs-bg-deletion-override: color-mix(in oklab, var(--danger) 8%, var(--well)); + --diffs-bg-deletion-number-override: color-mix(in oklab, var(--danger) 12%, var(--well)); + --diffs-bg-deletion-emphasis-override: color-mix(in oklab, var(--danger) 20%, var(--well)); --diffs-annotation-min-height: 0px; --diffs-font-family: var(--mono); --diffs-font-size: 12px; -- knotmirror 0.0.1