Skip to content

Commit 45de109

Browse files
soorriaclaude
andcommitted
fix(web): text after a composer list no longer joins its last item
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent dd6c05e commit 45de109

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎apps/web/src/composer-rich-text-doc.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe("composer rich text document model", () => {
303303
"- [ ] parent\n - [ ] child\n - [ ] sibling\n- [ ] uncle",
304304
"- [ ] empty task follows\n- [ ]",
305305
"- [ ] **bold** task with @README.md",
306-
"para\n- [ ] task\npara",
306+
"para\n- [ ] task\n\npara",
307307
"- [ ]No space stays literal",
308308
"-[ ] also literal",
309309
"@README.md explain this",
@@ -487,7 +487,7 @@ describe("composer rich text document model", () => {
487487
"- **bold** item with @README.md",
488488
"- [ ] task\n- bullet after",
489489
"- bullet\n- [x] task after",
490-
"para\n- item\npara",
490+
"- item\n indented continuation",
491491
"\t- tab indented\n\t- again",
492492
" - leading indent only",
493493
"- item\n\n- after a blank",
@@ -587,6 +587,16 @@ describe("composer rich text document model", () => {
587587
});
588588
});
589589

590+
it.each([
591+
["para\n- item\npara", "para\n- item\n\npara"],
592+
["1. one\n2. two\nafter", "1. one\n2. two\n\nafter"],
593+
["- [ ] task\nafter", "- [ ] task\n\nafter"],
594+
["- a\n - b\nafter", "- a\n - b\n\nafter"],
595+
])("separates %j from the list, or Markdown folds it into the last item", (glued, settled) => {
596+
expect(roundTrip(glued).value).toBe(settled);
597+
expect(roundTrip(settled).value).toBe(settled);
598+
});
599+
590600
it.each([
591601
"---",
592602
"***",

‎apps/web/src/composer-rich-text-doc.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,12 @@ function pushBreakRun(acc: RichAccumulator, position?: number): void {
10041004
acc.md += 1;
10051005
}
10061006

1007-
// Separate prose from quotes to avoid lazy continuation; an empty paragraph already separates them.
1008-
function needsBlankLineAfterQuote(previous: ProseMirrorNode, block: ProseMirrorNode): boolean {
1009-
return (
1010-
previous.type.name === "blockquote" && block.type.name === "paragraph" && block.content.size > 0
1011-
);
1007+
// Separate prose from quotes and lists to avoid lazy continuation; an empty paragraph already
1008+
// separates them. An indented line after a list continues the item on purpose.
1009+
function needsBlankLineBeforeParagraph(previous: ProseMirrorNode, block: ProseMirrorNode): boolean {
1010+
if (block.type.name !== "paragraph" || block.content.size === 0) return false;
1011+
if (previous.type.name === "blockquote") return true;
1012+
return LIST_NODE_NAMES.has(previous.type.name) && !/^[ \t]/.test(block.textContent);
10121013
}
10131014

10141015
// Blank-line runs own no document characters; offsets clamp to the paragraph start.
@@ -1454,7 +1455,7 @@ function serializeDoc(doc: ProseMirrorNode): RichDocMap {
14541455
let pmBlockStart = 0;
14551456
blocks.forEach((block, blockIndex) => {
14561457
if (blockIndex > 0 && !isTrailingLineAfterRule(doc, blockIndex)) pushBreakRun(acc);
1457-
if (blockIndex > 0 && needsBlankLineAfterQuote(blocks[blockIndex - 1]!, block)) {
1458+
if (blockIndex > 0 && needsBlankLineBeforeParagraph(blocks[blockIndex - 1]!, block)) {
14581459
pushBlankLineRun(acc, pmBlockStart + 1);
14591460
}
14601461
if (LIST_NODE_NAMES.has(block.type.name)) {

0 commit comments

Comments
 (0)