GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): a line typed after a composer list is sent after the list (… · pingdotgg/t3code@3e1b7c4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src
    • composer-list-split.browser.test.ts
    • composer-rich-text-doc.test.ts
    • composer-rich-text-doc.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/composer-list-split.browser.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/composer-list-split.browser.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function storedDraft(editor: Editor) {
6060

6161
describe("Backspace at the start of a line", () => {
6262
it.each([
63-
["- a\n```\nl1\nl2\n```", "- a\nl1\nl2"],
63+
["- a\n```\nl1\nl2\n```", "- a\n\nl1\nl2"],
6464
["p\n```ts\nl1\n```", "p\nl1"],
6565
])("removes the fence of %j rather than joining its code up", (value, expected) => {
6666
using editor = makeEditor(value);
@@ -95,6 +95,6 @@ describe("blocks that a list item or quote cannot hold", () => {
9595
editor.view.dispatch(editor.state.tr.setSelection(TextSelection.atEnd(editor.state.doc)));
9696
const lines = buildTiptapContent("one\ntwo", (name) => ({ label: name, description: null }));
9797
editor.commands.insertContent(lines);
98-
expect(storedDraft(editor)).toBe("- a\none\ntwo");
98+
expect(storedDraft(editor)).toBe("- a\n\none\ntwo");
9999
});
100100
});
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/composer-rich-text-doc.test.ts
+31-2Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe("composer rich text document model", () => {
315315
"- [ ] parent\n - [ ] child\n - [ ] sibling\n- [ ] uncle",
316316
"- [ ] empty task follows\n- [ ]",
317317
"- [ ] **bold** task with @README.md",
318-
"para\n- [ ] task\npara",
318+
"para\n- [ ] task\n\npara",
319319
"- [ ]No space stays literal",
320320
"-[ ] also literal",
321321
"@README.md explain this",
@@ -499,7 +499,7 @@ describe("composer rich text document model", () => {
499499
"- **bold** item with @README.md",
500500
"- [ ] task\n- bullet after",
501501
"- bullet\n- [x] task after",
502-
"para\n- item\npara",
502+
"para\n- item\n\npara",
503503
"\t- tab indented\n\t- again",
504504
" - leading indent only",
505505
"- item\n\n- after a blank",
@@ -608,6 +608,35 @@ describe("composer rich text document model", () => {
608608
});
609609
});
610610

611+
describe("a paragraph after a list", () => {
612+
const skillLabelFor = (name: string) => ({ label: name, description: null });
613+
it.each([
614+
["a numbered list", "1. a\n2. b\n3. c", 0],
615+
["a bullet list", "- a\n- b", 0],
616+
["a task list", "- [ ] a", 0],
617+
["a bullet list and an empty line", "- a", 1],
618+
])(
619+
"is written after a blank line after %s, or Markdown folds it into the last item",
620+
(_kind, list, emptyLines) => {
621+
const listJson = buildDocJson(list, skillLabelFor);
622+
const doc = ProseMirrorNode.fromJSON(schema, {
623+
type: "doc",
624+
content: [
625+
...listJson.content,
626+
...Array.from({ length: emptyLines }, () => ({ type: "paragraph" })),
627+
{ type: "paragraph", content: [{ type: "text", text: "d" }] },
628+
],
629+
});
630+
doc.check();
631+
expect(doc.childCount).toBe(2 + emptyLines);
632+
const { value } = serializeEditorDoc(doc);
633+
expect(value).toBe(`${list}\n\n${"\n".repeat(emptyLines)}d`);
634+
const reopened = ProseMirrorNode.fromJSON(schema, buildDocJson(value, skillLabelFor));
635+
expect(reopened.toJSON()).toEqual(doc.toJSON());
636+
},
637+
);
638+
});
639+
611640
describe("a dash rule after a paragraph", () => {
612641
const paragraph = (text: string) => ({ type: "paragraph", content: [{ type: "text", text }] });
613642
const rule = (source: string) => ({ type: "horizontalRule", attrs: { source } });
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/composer-rich-text-doc.ts
+26-7Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,21 @@ export function buildTiptapContent(
10901090
openQuote.content.push(entry.quote.inline);
10911091
continue;
10921092
}
1093-
// The serializer separates a quote from the prose after it with one blank line; it is not an empty paragraph.
1094-
const quoteSeparator =
1095-
openQuote !== null && isProseLine(entry, true) && isProseLine(entries[entryIndex + 1], false);
1093+
// The serializer separates a quote or list from the prose after it with one blank line; it is not an empty paragraph.
1094+
// After a list it precedes any empty paragraphs the user left, so those survive.
1095+
let proseIndex = entryIndex + 1;
1096+
if (openQuote === null && rootLists.length > 0 && isProseLine(entry, true)) {
1097+
while (isProseLine(entries[proseIndex], true)) proseIndex += 1;
1098+
}
1099+
const blockSeparator =
1100+
(openQuote !== null || rootLists.length > 0) &&
1101+
isProseLine(entry, true) &&
1102+
isProseLine(entries[proseIndex], false);
10961103
flushQuote();
1097-
if (quoteSeparator) continue;
1104+
if (blockSeparator) {
1105+
flushLists();
1106+
continue;
1107+
}
10981108
if ("code" in entry) {
10991109
flushLists();
11001110
blocks.push(entry.code);
@@ -1239,9 +1249,18 @@ function horizontalRuleSource(block: ProseMirrorNode): string {
12391249
return typeof source === "string" && source ? source : "---";
12401250
}
12411251

1242-
// A blank line keeps prose out of a quote (lazy continuation) and a dash rule from
1252+
// A blank line keeps prose out of a quote or list (lazy continuation) and a dash rule from
12431253
// underlining the line above into a setext heading; an empty paragraph already separates them.
1244-
function needsBlankLineBetween(previous: ProseMirrorNode, block: ProseMirrorNode): boolean {
1254+
function needsBlankLineBetween(blocks: readonly ProseMirrorNode[], index: number): boolean {
1255+
const previous = blocks[index - 1]!;
1256+
const block = blocks[index]!;
1257+
const isEmptyParagraph = (node: ProseMirrorNode | undefined) =>
1258+
node?.type.name === "paragraph" && node.content.size === 0;
1259+
if (LIST_NODE_NAMES.has(previous.type.name)) {
1260+
let next = index;
1261+
while (isEmptyParagraph(blocks[next])) next += 1;
1262+
return blocks[next]?.type.name === "paragraph";
1263+
}
12451264
if (previous.type.name === "blockquote") {
12461265
return block.type.name === "paragraph" && block.content.size > 0;
12471266
}
@@ -1718,7 +1737,7 @@ function serializeDoc(doc: ProseMirrorNode): RichDocMap {
17181737
let pmBlockStart = 0;
17191738
blocks.forEach((block, blockIndex) => {
17201739
if (blockIndex > 0 && !isTrailingLineAfterRule(doc, blockIndex)) pushBreakRun(acc);
1721-
if (blockIndex > 0 && needsBlankLineBetween(blocks[blockIndex - 1]!, block)) {
1740+
if (blockIndex > 0 && needsBlankLineBetween(blocks, blockIndex)) {
17221741
pushBlankLineRun(acc, pmBlockStart + 1);
17231742
}
17241743
if (LIST_NODE_NAMES.has(block.type.name)) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.