The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 03:00 UTC
fix(web): a comment under a composer quote no longer joins the quote (#19450)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
fixfon committed
Oct 18, 2026 at 22:34 UTC
02e9d2417a46e030f071cbb5b7d4c9fb23ac4933
2 files changed
+98
-1
apps/web/src/composer-rich-text-doc.test.ts
+62
-1
@@ -472,13 +472,74 @@ describe("composer rich text document model", () => {
472
"> **bold** and @README.md inside",
473
"> - looks like a list but stays quote text",
474
"> > nested stays literal inside the quote",
475
- "before\n> quoted\nafter",
475
+ "before\n> quoted",
476
"> quote\n\n> another",
477
"- item\n> quote after list",
478
+ "> quoted\n\ncomment",
479
+ "> line one\n> line two\n\ncomment",
480
])("round-trips the quote %s through a real ProseMirror document", (value) => {
481
expect(roundTrip(value).value).toBe(value);
482
});
483
484
+ describe("a paragraph after a quote", () => {
485
+ const paragraph = (text?: string) => ({
486
+ type: "paragraph",
487
+ ...(text ? { content: [{ type: "text", text }] } : {}),
488
+ });
489
+ const quote = (...lines: string[]) => ({
490
+ type: "blockquote",
491
+ attrs: { prefix: "> " },
492
+ content: lines.map((line) => paragraph(line)),
493
+ });
494
+ const serialize = (...content: object[]) => {
495
+ const doc = ProseMirrorNode.fromJSON(schema, { type: "doc", content });
496
+ doc.check();
497
+ return { doc, map: serializeEditorDoc(doc) };
498
+ };
499
+
500
+ it("is written after a blank line, or Markdown folds it into the quote", () => {
501
+ expect(serialize(quote("quoted"), paragraph("Comment to it")).map.value).toBe(
502
+ "> quoted\n\nComment to it",
503
+ );
504
+ expect(serialize(quote("a", "b"), paragraph("comment")).map.value).toBe(
505
+ "> a\n> b\n\ncomment",
506
+ );
507
+ });
508
+
509
+ it("does not double up on the empty line the user left themselves", () => {
510
+ expect(serialize(quote("quoted"), paragraph(), paragraph("Comment to it")).map.value).toBe(
511
+ "> quoted\n\nComment to it",
512
+ );
513
+ });
514
+
515
+ it("settles on the blank line when a draft glued it to the quote", () => {
516
+ const settled = "before\n> quoted\n\nafter";
517
+ expect(roundTrip("before\n> quoted\nafter").value).toBe(settled);
518
+ expect(roundTrip(settled).value).toBe(settled);
519
+ });
520
+
521
+ it.each(["# Heading", "- item", "3. item", "---", "```\ncode\n```"])(
522
+ "leaves %s on the next line, since it opens its own block",
523
+ (next) => {
524
+ const value = `> quoted\n${next}`;
525
+ expect(roundTrip(value).value).toBe(value);
526
+ },
527
+ );
528
+
529
+ it("keeps every offset mapped through the blank line", () => {
530
+ const { doc, map } = serialize(quote("quoted"), paragraph("Comment"));
531
+ for (let flat = 0; flat <= map.docLength; flat += 1) {
532
+ expect(collapsedToFlat(map, flatToCollapsed(map, flat))).toBe(flat);
533
+ }
534
+ // The caret on the end of the quote stays on it, and the blank line is
535
+ // not a place to type: it clamps to the start of the comment.
536
+ expect(flatToCollapsed(map, "quoted".length)).toBe("> quoted".length);
537
+ expect(collapsedToFlat(map, "> quoted\n".length)).toBe("quoted".length + 1);
538
+ expect(flatToCollapsed(map, "quoted".length + 1)).toBe("> quoted\n\n".length);
539
+ expect(flatToPm(map, "quoted".length + 1)).toBe(doc.child(0).nodeSize + 1);
540
+ });
541
+ });
542
+
543
it.each([
544
"---",
545
"***",
apps/web/src/composer-rich-text-doc.ts
+36
@@ -741,6 +741,39 @@ function pushBreakRun(acc: RichAccumulator, position?: number): void {
741
acc.md += 1;
742
}
743
744
+/**
745
+ * A paragraph on the line right after a quote reads as part of it in Markdown
746
+ * (a lazy continuation), so the draft writes a blank line between them. An empty
747
+ * paragraph is that blank line already.
748
+ */
749
+function needsBlankLineAfterQuote(previous: ProseMirrorNode, block: ProseMirrorNode): boolean {
750
+ return (
751
+ previous.type.name === "blockquote" && block.type.name === "paragraph" && block.content.size > 0
752
+ );
753
+}
754
+
755
+/**
756
+ * That blank line, as a run that owns no document characters, like a marker:
757
+ * offsets inside it clamp to the start of the paragraph.
758
+ */
759
+function pushBlankLineRun(acc: RichAccumulator, pmPos: number): void {
760
+ acc.runs.push({
761
+ kind: "prefix",
762
+ flatStart: acc.flat,
763
+ docLen: 0,
764
+ collapsedLen: 1,
765
+ mdLen: 1,
766
+ openLen: 0,
767
+ closeLen: 0,
768
+ pmPos,
769
+ mdStart: acc.md,
770
+ collapsedStart: acc.collapsed,
771
+ });
772
+ acc.value += "\n";
773
+ acc.collapsed += 1;
774
+ acc.md += 1;
775
+}
776
+
777
function appendInlineRuns(
778
container: ProseMirrorNode,
779
contentStart: number,
@@ -1197,6 +1230,9 @@ export function serializeEditorDoc(doc: ProseMirrorNode): RichDocMap {
1230
let pmBlockStart = 0;
1231
blocks.forEach((block, blockIndex) => {
1232
if (blockIndex > 0 && !isTrailingLineAfterRule(doc, blockIndex)) pushBreakRun(acc);
1233
+ if (blockIndex > 0 && needsBlankLineAfterQuote(blocks[blockIndex - 1]!, block)) {
1234
+ pushBlankLineRun(acc, pmBlockStart + 1);
1235
+ }
1236
if (LIST_NODE_NAMES.has(block.type.name)) {
1237
walkList(block, pmBlockStart, acc);
1238
} else if (block.type.name === "codeBlock") {