Columns: a column's adopt goes by child, so the caret stays in its block (Fable round 3)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+26
−18
docs/superpowers/specs/2026-11-22-mapa-columns-icons.md+1 −0editor/columns.test.mjs+4 −1editor/fidelity.mjs+19 −15internal/mapa/markup/testdata/editor.json+2 −2
diff --git a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md| index fdb80e9..d6d6918 100644 |
| --- a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| +++ b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| @@ -780,4 +780,5 @@ Fable found every round-1 finding answered in substance, and five mediums and si |
| - L5: one existing golden entry, `import/columns`, changed on purpose: the importer now writes that fixture as a layout. Every other existing entry is unchanged (COL1). |
| - Not taken: L1 (`fenceRule` neutralises every fence-like text line when one would make a layout, untouched ones included: rare, and it errs safe), L3 (net counts in History's layout summary), L4 (an empty paragraph left above a removed column's blocks until reload), L6 (C6's menus). |
| - **C11, Fable's round 2 on the fixes (`a768523`): CHANGES REQUIRED, two mediums in `adoptColumn`, answered.** The caret now keeps its place after a column's adopt (typing went into the next column), and the neutraliser skips code. A longer fence for code written from its node did nothing (the parser's fence is its first three characters) and is gone. Lows not taken: no test lists every handler that reads an index (the four routes are wrapped by name and COL13 posts to each); a paste over a cross-column selection deletes before the paste is known to succeed; drag and drop across columns is not confined. |
| +- **C12, Fable's round 3 (`eb7dc12`): one medium, answered.** The caret after a column's adopt could land at the start of the block after the edited one, since the whole column was replaced. `adoptColumn` now adopts the column by child, as `adoptInto` does at the top level (`adoptInto` takes a container): blocks the parse still has stay as they are, origins included, only the changed run is replaced, and the caret is measured against that run. The test now places the caret and checks the typed text lands in its block, as the top level does. |
diff --git a/editor/columns.test.mjs b/editor/columns.test.mjs| index 5a5a067..9aaaaf6 100644 |
| --- a/editor/columns.test.mjs |
| +++ b/editor/columns.test.mjs |
| @@ -223,10 +223,13 @@ test('typing goes on in the column after a structural reparse (round 2)', () => |
| const { view, fidelity } = editor(body) |
| const pos = textPos(view, 'Alpha') + 'Alpha.'.length |
| view.dispatch(view.state.tr.insert(pos, view.state.schema.nodes.hard_break.create())) |
| + at(view, pos + 1) |
| for (const char of '- item') view.dispatch(view.state.tr.insertText(char)) |
| const out = saved(view, fidelity) |
| assert.match(out, /::: column\nRight\.\n/u, JSON.stringify(out)) |
| - assert.match(out, /- item/u) |
| + // What the top level gives for the same typing ("Alpha.item"), in the |
| + // block typed in: the caret never moves to the block after it. |
| + assert.match(out, /::: column\nAlpha\.item\n\nSecond\.\n/u, JSON.stringify(out)) |
| }) |
| test('a structural reparse in a column leaves code as it was (round 2)', () => { |
diff --git a/editor/fidelity.mjs b/editor/fidelity.mjs| index cfdf1c4..0276e23 100644 |
| --- a/editor/fidelity.mjs |
| +++ b/editor/fidelity.mjs |
| @@ -178,13 +178,18 @@ function childKey (node, schema) { |
| // empty block you are typing in); the rest are replaced by body's, with |
| // fresh origins recorded from body. The selection, when it was in a |
| // replaced run, keeps its distance from the end of that run. |
| -export function adoptInto (tr, fidelity, body) { |
| +export function adoptInto (tr, fidelity, body, within = null) { |
| const schema = tr.doc.type.schema |
| - const { doc: target } = recordBody(schema, fidelity, body) |
| + // within is a column: its children are adopted, not the document's |
| + // (§1.7 rule 4), at their place inside it. |
| + const container = within ? within.node : tr.doc |
| + const base = within ? within.start : 0 |
| + const { doc: target } = recordBody(schema, fidelity, body, |
| + within ? { trailing: false, edges: false } : {}) |
| const old = [] |
| - tr.doc.forEach((node, offset) => { |
| + container.forEach((node, offset) => { |
| const key = childKey(node, schema) |
| - if (key !== '[]') old.push({ node, offset, key }) |
| + if (key !== '[]') old.push({ node, offset: offset + base, key }) |
| }) |
| const neu = [] |
| target.forEach(node => { |
| @@ -200,7 +205,7 @@ export function adoptInto (tr, fidelity, body) { |
| if (pair[0] > oldStart || pair[1] > neuStart) { |
| const from = oldStart < old.length |
| ? old[oldStart].offset |
| - : (old[old.length - 1] ? old[old.length - 1].offset + old[old.length - 1].node.nodeSize : 0) |
| + : (old[old.length - 1] ? old[old.length - 1].offset + old[old.length - 1].node.nodeSize : base) |
| const to = pair[0] > oldStart |
| ? old[pair[0] - 1].offset + old[pair[0] - 1].node.nodeSize |
| : from |
| @@ -639,17 +644,16 @@ function adoptColumn (tr, fidelity, block) { |
| const schema = tr.doc.type.schema |
| const own = schema.topNodeType.create(null, column.content) |
| const text = neutralLines(serialiseDetailed(own, fidelity, { edges: false, raw: true }).body) |
| - const { doc } = recordBody(schema, fidelity, text, { trailing: false, edges: false }) |
| - const content = doc.childCount ? doc.content : Fragment.from(schema.nodes.paragraph.create()) |
| - // The caret keeps its distance from the column's end, as adoptInto |
| - // keeps it from a replaced run's (Fable on the build, round 2). |
| - const head = tr.selection.head |
| - const left = head >= start && head <= end ? inlineLength(tr.doc, head, end) : null |
| - tr.replaceWith(start, end, content) |
| - if (left !== null) { |
| - const at = posBeforeEnd(tr.doc, start, start + content.size, left) |
| - tr.setSelection(TextSelection.near(tr.doc.resolve(at), -1)) |
| + // By child, as at the top level: the column's blocks the parse still |
| + // has stay as they are, origins and all, only the changed run is |
| + // replaced, and the caret keeps its distance from that run's end |
| + // (Fable on the build, round 3). |
| + adoptInto(tr, fidelity, text, { node: column, start }) |
| + const after = tr.doc.nodeAt(start - 1) |
| + if (after && after.type.name === 'column' && after.childCount === 0) { |
| + tr.insert(start, schema.nodes.paragraph.create()) |
| } |
| + void end |
| } |
| // neutralLines puts U+200B before the first ":" of every fence-like |
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json| index 3a4af9f..92b1356 100644 |
| --- a/internal/mapa/markup/testdata/editor.json |
| +++ b/internal/mapa/markup/testdata/editor.json |
| @@ -220,8 +220,8 @@ |
| {"name":"columns/two","body":":::: columns\n\n::: column\nLef*t*.\n\n- on\n- \ne\n- two\n\n\n:::\n\n::: column\n[[Acme#^b1|that]]\n\n- twof*t*.\n - on\ne\n - two\n - two\n\nRight\n\nRight\n\n:::\n\n::::","blocks":["columns","column","paragraph","item:bullet_list:0:true","item:bullet_list:0:false","item:bullet_list:0:false","column_end","column","paragraph","item:bullet_list:0:true","item:bullet_list:1:true","item:bullet_list:1:false","item:bullet_list:1:false","paragraph","paragraph","column_end","columns_end"]}, |
| {"name":"columns/three-empty","body":":::: columns\n::: column\n- [x] \n[[Acme]]\n\n:::\n::: column\nB- ```\n:::\n::: column\n```\n:::\n```\n:::\n::::\n\n:::: columns\n\n::: column\n[[Acme]]\n\n:::\n\n::: column\n```\n:::\n```\n\n:::\n\n::::\n\n\n[[2026-11-12]]","blocks":["columns","column","item:bullet_list:0:true","column_end","column","paragraph","column_end","column","code","column_end","columns_end","columns","column","paragraph","column_end","column","code","column_end","columns_end","paragraph"]}, |
| {"name":"columns/four","body":":::: columns\n\n::: column\n[[Halden Robotics]]A![[fichas:c1]]\n\n:::\n\n::: column\n:::\n\n::::\n\n:::: columns\n\n::: column\n![[fichas:c1]][[Halden Robotics]]A![[fichas:c1]]\n\n:::\n\n::: column\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","column_end","columns_end","columns","column","paragraph","column_end","column","column_end","columns_end"]}, |
| -{"name":"columns/longer-fences","body":"::::: columns\n:::: column\nA> `A`\n\nB\n\n::::\n:::: column\n~~~B\n~~~\n\n::::\n\n::: column\n1. \n\n:::\n\n:::::","blocks":["columns","column","paragraph","paragraph","column_end","column","code","column_end","column","item:ordered_list:0:true","column_end","columns_end"]}, |
| -{"name":"columns/around","body":"**Be**f\n\n:::: columns\n\n::: column\n#### Hea****Be**f\n\n:::: columns\n\n::: column\n# Hea\nd\n\n:::\n\n[x](https://x.y)::::\n\n:::\n\n::: column\n[[Acme#^b1|that]]|\n\n:::\n\n::::\n\né","blocks":["paragraph","columns","column","heading:4","paragraph","paragraph","heading:1","paragraph","paragraph","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph"]}, |
| +{"name":"columns/longer-fences","body":"::::: columns\n:::: column\nAA\n\nB\n\n::::\n:::: column\nB\n::::\n\n::: column\n~~~\n~~~\n\n:::\n\n::: column\n:::\n\n:::::\n\n::::: columns\n\n:::: column\n::::\n\n::: column\n~~~\n~~~\n\n:::\n\n:::::","blocks":["columns","column","paragraph","paragraph","column_end","column","paragraph","column_end","column","code","column_end","column","column_end","columns_end","columns","column","column_end","column","code","column_end","columns_end"]}, |
| +{"name":"columns/around","body":"**Be**f\n\n:::: columns\n\n::: column\n#### Hea****Be**f\n\n:::: columns\n\n::: column\n\n# Hea\nd\n\n:::\n\n[x](https://x.y)::::\n\n:::\n\n::: column\n[[Acme#^b1|that]]|\n\n:::\n\n::::\n\né","blocks":["paragraph","columns","column","heading:4","paragraph","paragraph","heading:1","paragraph","paragraph","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph"]}, |
| {"name":"columns/image","body":":::: columns\n\n::: column\n*word *- \n\n:::\n\n::: column\n*e[x](https://x.y)m*\n\n:::\n\n::::\n\n:::: columns\n\n::: column\n*word *- \n\n*e[x](https://x.y)m*\n\n:::\n\n::: column\n*e[x](https://x.y)m*\n\n:::\n\n::::\n\n`","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end","columns","column","paragraph","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph"]}, |
| {"name":"columns/crlf","body":":::: columns\n\n::: column\n```A\n```\n\n:::\n\n::: column\nB> ^ab\n\n:::\n\n::::\n\n:::: columns\n\n::: column\n1. A\n\n:::\n\n::: column\n[ ] \n\nB> \n\n:::\n\n::::","blocks":["columns","column","code","column_end","column","paragraph","column_end","columns_end","columns","column","item:ordered_list:0:true","column_end","column","paragraph","paragraph","column_end","columns_end"]}, |
| {"name":"columns/one","body":":[[2026-11-12]]::: co[x](https://x.y)l~~~um\n\nns\n\n::: \ncolumn\n\n:::\n\n:::::[[2026-11-12]]::: col~~~um\n\nns\n\n::: column","blocks":["paragraph","paragraph","paragraph","paragraph","paragraph","paragraph","paragraph"]}, |