iterate.com / git

git clone https://git.iterate.com/repos/git

Comments on a range of lines, a "+" that goes away, and fewer boxes

A comment in a diff was on one line. Dragging pierre's button beside a
line now takes every line it passes, and the comment is on those lines:
its place has `endLine`, its quote is all of them, and it stays on them
while each still reads the same. A range is lines of one side of the
diff; a drag from the old lines to the new ones is its last line alone.

The button stayed beside a line after Cancel, and after a comment was
sent: pierre kept the line as chosen. The page now says which lines are
chosen (the draft's, or none).

A border is now a thread's or a text field's, and nothing else's. The
pull's body, the comment box and the box under a line had one each, so
a text field sat in a box in a box.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Misha Kaletsky, 2026-11-24 22:54 UTC · 4333e93289f6ff72f56972a932cb75e1686ccfa1 · parent e567719

5 files changed

M pages.ts
@@ -384,7 +384,7 @@
       changes = await keptChanges(view, handle, itx, stand.base, stand.head);
   }
 
-  // A comment on a line stays on the line while the line still reads as it did.
+  // A comment on lines stays on them while they still read as they did.
   const threads = pull.threads.map((thread) => {
     const now = thread.place ? lineNow(changes, thread.place) : null;
     const outdated = Boolean(thread.place && now?.text !== thread.place.quote);
@@ -392,7 +392,7 @@
   });
   const conversation = threads.map((thread) => {
     const place = thread.place
-      ? `<p class="place">${thread.diff === null ? "" : `<a href="#diff-${thread.diff}">`}<code>${esc(thread.place.path)}</code>${thread.diff === null ? "" : "</a>"} line ${thread.place.line}${thread.outdated ? ", which has changed since" : ""}<code class="quote">${esc(thread.place.quote)}</code></p>`
+      ? `<p class="place">${thread.diff === null ? "" : `<a href="#diff-${thread.diff}">`}<code>${esc(thread.place.path)}</code>${thread.diff === null ? "" : "</a>"} ${linesOf(thread.place)}${thread.outdated ? ", changed since" : ""}<code class="quote">${esc(thread.place.quote)}</code></p>`
       : "";
     const comments = thread.comments.map(
       (comment) =>
@@ -445,14 +445,14 @@
   return `<p class="by"><code>${esc(branch)}</code> adds ${adds} to <code>main</code>.</p>${moved}`;
 }
 
-/** The text now on the line a comment was made on, and which file of the page it is in; null
- *  when the page shows no such line. */
+/** The text now on the lines a comment was made on, and which file of the page they are in;
+ *  null when the page shows no such file. */
 function lineNow(changes: Change[], place: LinePlace) {
   const diff = changes.findIndex(({ path }) => path === place.path);
   const sides = diff < 0 ? null : changes[diff]!.sides;
   if (!sides) return null;
   const lines = (place.side === "additions" ? sides.after : sides.before).split("\n");
-  return { diff, text: lines[place.line - 1] };
+  return { diff, text: lines.slice(place.line - 1, place.endLine).join("\n") };
 }
 
 // ── THE DIFFERENCE BETWEEN TWO COMMITS ──
@@ -614,6 +614,9 @@
 const utcStamp = (timestamp: number) =>
   `${new Date(timestamp).toISOString().slice(0, 16).replace("T", " ")} UTC`;
 
+/** `line 4`, or `lines 4 to 6`. */
+const linesOf = (place: LinePlace) =>
+  place.endLine > place.line ? `lines ${place.line} to ${place.endLine}` : `line ${place.line}`;
 /** The page that compares a branch with main. */
 const compareHref = (repo: string, branch: string) =>
   esc(`${repo}/compare/${branch.split("/").map(encodeURIComponent).join("/")}`);
M public/page.css
@@ -73,35 +73,33 @@
 .pull .changes { margin-bottom: 1.5rem; }
 .tag.open { color: light-dark(oklch(0.5 0.15 150), oklch(0.75 0.15 150)); }
 .tag.merged { color: light-dark(oklch(0.5 0.15 300), oklch(0.75 0.15 300)); }
-.body, .thread, .box { border: 1px solid var(--border); border-radius: 0.5rem; }
-.body { margin: 0.75rem 0; padding: 0.75rem 1rem; }
-.thread { margin: 0.5rem 0; max-width: 46rem; background: var(--background);
+/* A BORDER IS A THREAD'S OR A TEXT FIELD'S, and nothing else's: a box that writes has none. */
+.body { margin: 0.75rem 0 1rem; max-width: 46rem; }
+.body .markdown { padding: 0; }
+.thread { margin: 0.5rem 0; max-width: 46rem; border: 1px solid var(--border);
+  border-radius: 0.5rem; background: var(--background);
   font-family: var(--font-sans, system-ui, sans-serif); font-size: 0.8125rem; white-space: normal; }
 .thread.resolved { opacity: 0.6; }
 .thread .place { padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border);
   color: var(--muted-foreground); font-size: 0.75rem; }
-.thread .quote { display: block; margin-top: 0.25rem; overflow: hidden; text-overflow: ellipsis;
+.thread .quote { display: block; max-height: 7.5rem; margin-top: 0.25rem; overflow: auto;
   white-space: pre; color: var(--foreground); }
 .comment { padding: 0.5rem 0.75rem; }
-.comment + .comment { border-top: 1px solid var(--border); }
 .comment .by { margin-bottom: 0.25rem; font-size: 0.75rem; }
 .comment pre { white-space: pre-wrap; font-family: inherit; font-size: inherit; }
-.thread .actions { position: relative; padding: 0.4rem 0.75rem;
-  border-top: 1px solid var(--border); }
-.reply summary { display: inline-block; cursor: pointer; color: var(--muted-foreground); }
+.thread .actions { position: relative; padding: 0.25rem 0.75rem 0.5rem; }
+.reply summary { display: inline-block; cursor: pointer; color: var(--muted-foreground);
+  font-size: 0.75rem; }
 .reply[open] summary { margin-bottom: 0.5rem; }
-/* beside "Reply", wherever the reply box is open or shut */
-.thread .resolve { position: absolute; top: 0.3rem; right: 0.75rem; padding: 0.1rem 0.6rem;
+/* beside "Reply", whether the reply box is open or shut */
+.thread .resolve { position: absolute; top: 0.1rem; right: 0.75rem; padding: 0.1rem 0.6rem;
   font-size: 0.75rem; }
-.thread .reply .box { padding: 0; border: 0; }
-/* a thread on a line of a diff: pierre lays it out under the line */
-.diff .thread { margin: 0.5rem; }
+/* a thread or a draft on lines of a diff: pierre lays it out under the last of them */
+.diff .thread, .diff .box { margin: 0.5rem; }
 
-.box { display: grid; gap: 0.5rem; max-width: 46rem; margin: 0.75rem 0; padding: 0.75rem;
-  background: var(--background); font-family: var(--font-sans, system-ui, sans-serif);
-  font-size: 0.8125rem; white-space: normal; }
-
-.diff .box { margin: 0.5rem; }
+.box { display: grid; gap: 0.5rem; max-width: 46rem; margin: 0.75rem 0;
+  font-family: var(--font-sans, system-ui, sans-serif); font-size: 0.8125rem; white-space: normal; }
+.thread .box { margin: 0; }
 .box input, .box textarea { width: 100%; padding: 0.4rem 0.6rem; border: 1px solid var(--input);
   border-radius: 0.375rem; background: var(--background); font: inherit; }
 .box textarea { min-height: 4.5rem; resize: vertical; }
@@ -114,5 +112,5 @@
   color: var(--primary-foreground); }
 button:disabled { opacity: 0.5; cursor: default; }
 .merge { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
-.merge .box { margin: 0; padding: 0; border: 0; }
+.merge .box { margin: 0; }
 h1 code { font-size: 0.9em; }
M public/page.js
@@ -118,8 +118,9 @@
  *  a line has `place` and `diff`, the file of this page it is in; `outdated` says the line has
  *  changed since. */
 const threads = data.threads || [];
-/** A comment being written on a line: `{ diff, side, line }`. */
-const drafts = [];
+/** The comment being written on lines of a diff, by the diff's number on the page: `{ diff, side,
+ *  line, endLine }`. One for each file at a time: pierre marks one range of lines as chosen. */
+const drafts = new Map();
 
 const stamp = (at) => new Date(at).toISOString().slice(0, 16).replace("T", " ") + " UTC";
 const said = (event, body) => ({ id: event.offset, by: data.me, at: event.createdAt, body });
@@ -127,7 +128,7 @@
 async function comment(body, place, draft) {
   const pull = data.pull.number;
   const event = await append("pull/commented", { pull, body: body.trim(), replyTo: null, at: place });
-  if (draft) drafts.splice(drafts.indexOf(draft), 1);
+  if (draft) drafts.delete(draft.diff);
   const diff = draft ? draft.diff : null;
   threads.push({ id: event.offset, place, diff, outdated: false, resolved: false, comments: [said(event, body.trim())] });
   redraw();
@@ -153,7 +154,7 @@
     place &&
     html`<p className="place">
       ${thread.diff === null ? html`<code>${place.path}</code>` : html`<a href=${"#diff-" + thread.diff}><code>${place.path}</code></a>`}
-      ${" line " + place.line}${thread.outdated ? ", which has changed since" : ""}
+      ${place.endLine > place.line ? " lines " + place.line + " to " + place.endLine : " line " + place.line}${thread.outdated ? ", changed since" : ""}
       <code className="quote">${place.quote}</code>
     </p>`;
   // the reply box opens under "Reply": a thread is read far more often than answered
@@ -193,21 +194,34 @@
   </div>`;
 }
 
-/** The box under a line of a diff where a member writes a comment on that line. */
+/** The box under the lines of a diff that a member chose, where they write a comment on them. */
 function Draft({ draft }) {
   const { path, before, after } = data.diffs[draft.diff];
-  // the line's own text goes with the comment: the comment stays on the line while it reads so
-  const quote = (draft.side === "additions" ? after : before).split("\n")[draft.line - 1] || "";
-  const place = { path, side: draft.side, line: draft.line, quote };
+  // the lines' own text goes with the comment: the comment stays on them while they read so
+  const lines = (draft.side === "additions" ? after : before).split("\n");
+  const quote = lines.slice(draft.line - 1, draft.endLine).join("\n");
+  const place = { path, side: draft.side, line: draft.line, endLine: draft.endLine, quote };
   const discard = () => {
-    drafts.splice(drafts.indexOf(draft), 1);
+    drafts.delete(draft.diff);
     drawDiff(draft.diff);
   };
+  const lineWords = draft.endLine > draft.line ? "these lines" : "this line";
   return html`<${Form} button="Comment" send=${({ text }) => comment(text, place, draft)} cancel=${discard}>
-    <textarea name="text" placeholder="Comment on this line" required autoFocus></textarea>
+    <textarea name="text" placeholder=${"Comment on " + lineWords} required autoFocus></textarea>
   <//>`;
 }
 
+/** The lines a member chose with pierre's button beside a line (a click for one line, a drag for
+ *  several), as a draft. A comment is on lines of one side of the diff: a drag that goes from the
+ *  old lines to the new ones is its last line alone. */
+function draftOf(diff, range) {
+  const side = range.endSide || range.side || "additions";
+  const oneSide = (range.side || side) === side;
+  const line = oneSide ? Math.min(range.start, range.end) : range.end;
+  const endLine = oneSide ? Math.max(range.start, range.end) : range.end;
+  return { diff, side, line, endLine };
+}
+
 /** The buttons of an open pull. A squash is offered while the branch has main's newest commit. */
 function MergeBox() {
   const merge = async () => {
@@ -253,10 +267,12 @@
     options: {
       ...pierre,
       diffStyle: "unified",
-      // a member comments on a line of a pull: the button that pierre shows beside the line
+      // a member comments on lines of a pull: the button that pierre shows beside a line, which
+      // a click takes for that line and a drag for every line it passes
       enableGutterUtility: Boolean(data.pull && data.me),
+      enableLineSelection: Boolean(data.pull && data.me),
       onGutterUtilityClick: (range) => {
-        drafts.push({ diff: index, side: range.side || "additions", line: range.start });
+        drafts.set(index, draftOf(index, range));
         drawDiff(index);
       },
     },
@@ -265,11 +281,18 @@
   };
   diffProps.set(index, fixed);
   const here = threads.filter((thread) => thread.diff === index && !thread.outdated && !thread.resolved);
+  const draft = drafts.get(index);
+  // a thread and a draft stand under the last of their lines
   const lineAnnotations = [
-    ...here.map((thread) => ({ side: thread.place.side, lineNumber: thread.place.line, metadata: { thread } })),
-    ...drafts.filter((draft) => draft.diff === index).map((draft) => ({ side: draft.side, lineNumber: draft.line, metadata: { draft } })),
+    ...here.map((thread) => ({ side: thread.place.side, lineNumber: thread.place.endLine, metadata: { thread } })),
+    ...(draft ? [{ side: draft.side, lineNumber: draft.endLine, metadata: { draft } }] : []),
   ];
-  diffRoots.get(index).render(html`<${MultiFileDiff} ...${fixed} lineAnnotations=${lineAnnotations} />`);
+  // The lines of the draft are the chosen ones, and with no draft none is: pierre keeps its own
+  // choice, and its button beside it, until it is told.
+  const selectedLines = draft ? { start: draft.line, end: draft.endLine, side: draft.side, endSide: draft.side } : null;
+  diffRoots.get(index).render(
+    html`<${MultiFileDiff} ...${fixed} lineAnnotations=${lineAnnotations} selectedLines=${selectedLines} />`,
+  );
 }
 
 // Each diff is drawn when the reader scrolls near it: a commit may change many files.
M pulls.ts
@@ -6,7 +6,7 @@
 //
 //   pull/opened     { branch, title, body }
 //   pull/edited     { pull, title, body }
-//   pull/commented  { pull, body, replyTo, at }     at: { path, side, line, quote }, or null
+//   pull/commented  { pull, body, replyTo, at }     at: { path, side, line, endLine, quote }, or null
 //   pull/resolved   { pull, comment }
 //   pull/merged     { pull, commitOid }
 //   pull/closed     { pull }
@@ -35,15 +35,19 @@
 type Repo = ReturnType<Itx["repos"]["get"]>;
 type Files = Awaited<ReturnType<Repo["files"]>>;
 
-/** Where a comment on a line is: the file, the side of the diff, the line's number on that side,
- *  and the line's text when the comment was written. The comment stays on the line while the line
- *  still reads so. */
-const LinePlace = z.object({
-  path: z.string().min(1),
-  side: z.enum(["additions", "deletions"]),
-  line: z.number().int().positive(),
-  quote: z.string(),
-});
+/** Where a comment on lines is: the file, the side of the diff, the first line's number on that
+ *  side and the last one's (`endLine`, which a comment on one line may leave out), and the text
+ *  of those lines when the comment was written. The comment stays on its lines while they still
+ *  read so. */
+const LinePlace = z
+  .object({
+    path: z.string().min(1),
+    side: z.enum(["additions", "deletions"]),
+    line: z.number().int().positive(),
+    endLine: z.number().int().positive().optional(),
+    quote: z.string(),
+  })
+  .transform((place) => ({ ...place, endLine: Math.max(place.endLine || place.line, place.line) }));
 export type LinePlace = z.infer<typeof LinePlace>;
 
 const Opened = z.object({ branch: z.string().min(1), title: z.string().min(1), body: z.string() });
M tests/pulls.test.mjs
@@ -106,7 +106,7 @@
       {
         // the comment on a line: on the page's first file, where the line still reads the same
         id: 3,
-        place: line,
+        place: { ...line, endLine: 1 },
         resolved: true,
         comments: [
           { id: 3, by: "grace", at: "2026-11-24T12:03:00.000Z", body: "Why not `crimson`?" },
@@ -195,29 +195,40 @@
   );
 });
 
-test("a comment on a line stays on its line while the line reads as it did, and says so when the line has changed", async () => {
+test("a comment on lines stays on them while they read as they did, and says so when one of them has changed", async () => {
   using site = repoWith([
-    { message: "Start", files: { "header.css": "header { color: black; }\n" } },
-    { on: "red-header", message: "Red", files: { "header.css": "header { color: red; }\n" } },
+    { message: "Start", files: { "header.css": "header {\n  color: black;\n}\n" } },
+    { on: "red-header", message: "Red", files: { "header.css": "header {\n  color: red;\n  margin: 0;\n}\n" } },
   ]);
   const repo = "/repos/site";
   const mind = localMind({ folders: { [repo]: site.folder }, member: "ada@example.com" });
   const git = gitApp({ public: [repo], ...look });
+  const page = async () =>
+    (await git.fetch(new Request("https://git.example.com/repos/site/pull/1"), mind)).text();
   const threads = async () =>
-    dataOf(await (await git.fetch(new Request("https://git.example.com/repos/site/pull/1"), mind)).text())
-      .threads.map(({ diff, outdated }) => ({ diff, outdated }));
+    dataOf(await page()).threads.map(({ place, diff, outdated }) => ({ lines: [place.line, place.endLine], diff, outdated }));
   const ada = mind.as("ada@example.com").cd(repo);
   await ada.append({ type: "pull/opened", payload: { branch: "red-header", title: "Red", body: "" } });
-  const line = { path: "header.css", side: "additions", line: 1, quote: "header { color: red; }" };
-  await ada.append({ type: "pull/commented", payload: { pull: 1, body: "Too bright?", replyTo: null, at: line } });
+  // one comment on the two new lines, and one on the last line alone, which names no end
+  const two = { path: "header.css", side: "additions", line: 2, endLine: 3, quote: "  color: red;\n  margin: 0;" };
+  const one = { path: "header.css", side: "additions", line: 4, quote: "}" };
+  await ada.append({ type: "pull/commented", payload: { pull: 1, body: "Too bright?", replyTo: null, at: two } });
+  await ada.append({ type: "pull/commented", payload: { pull: 1, body: "Fine.", replyTo: null, at: one } });
 
-  assert.deepEqual(await threads(), [{ diff: 0, outdated: false }]);
+  assert.deepEqual(await threads(), [
+    { lines: [2, 3], diff: 0, outdated: false },
+    { lines: [4, 4], diff: 0, outdated: false },
+  ]);
+  assert.ok((await page()).includes(`</a> lines 2 to 3<code class="quote">  color: red;\n  margin: 0;</code>`));
 
-  // a new commit on the branch changes that line
-  site.more({ on: "red-header", message: "Crimson", files: { "header.css": "header { color: crimson; }\n" } });
-  assert.deepEqual(await threads(), [{ diff: 0, outdated: true }]);
-  const html = await (await git.fetch(new Request("https://git.example.com/repos/site/pull/1"), mind)).text();
-  assert.ok(html.includes(`line 1, which has changed since<code class="quote">header { color: red; }</code>`));
+  // a new commit on the branch changes one of the two lines, and leaves the last line as it was
+  site.more({ on: "red-header", message: "Crimson", files: { "header.css": "header {\n  color: crimson;\n  margin: 0;\n}\n" } });
+
+  assert.deepEqual(await threads(), [
+    { lines: [2, 3], diff: 0, outdated: true },
+    { lines: [4, 4], diff: 0, outdated: false },
+  ]);
+  assert.ok((await page()).includes(`</a> lines 2 to 3, changed since<code class="quote">  color: red;\n  margin: 0;</code>`));
 });
 
 test("a squash is taken only while the branch has main's newest commit: when main has moved, the branch merges main in first", async () => {