Columns: the caret and code survive a column's adopt (Fable round 2)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+63
−22
docs/superpowers/specs/2026-11-22-mapa-columns-icons.md+2 −1editor/columns.test.mjs+22 −0editor/fidelity.mjs+32 −4editor/serialize.mjs+2 −12internal/mapa/markup/testdata/editor.json+5 −5
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 0fd6ec7..fdb80e9 100644 |
| --- a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| +++ b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| @@ -771,7 +771,7 @@ Fable found every round-1 finding answered in substance, and five mediums and si |
| - **C9, COL12.** Pandoc 3.14 reads every layout Mapa recognises, and Join's output for each, as Mapa does; the negatives are recorded. Fence-like text Mapa writes as text (no escapes) is divs to Pandoc; that is outside the promise. |
| - **C10, Fable on the build (`bedb7ca`): CHANGES REQUIRED, 2 high, 7 medium, answered.** |
| - H1: Insert → Columns over a selection that held a layout nested one. The layout now gives up its columns' blocks into column 1, and the nodes are built checked. |
| - - H2: a structural reparse in a column adopted the whole body, and code holding a fence line closed early, both turning the layout into text. A structural reparse inside a column now parses that column's own lines, neutralised, and replaces only its content (§1.7 rule 4, `adoptColumn`); and code written from its node takes a longer fence when a line of it would close the fence early. |
| + - H2: a structural reparse in a column adopted the whole body, turning the layout into text. A structural reparse inside a column now parses that column's own lines, written with their sources and neutralised outside code, and replaces only that column's content, keeping the caret's distance from its end (§1.7 rule 4, `adoptColumn`). |
| - M1, M2: a layout pasted into a column arrives as its blocks; copying inside one column puts no fence on the clipboard. |
| - M3, M4: a selection across columns is deleted column by column, never deleting a column (Backspace, Delete, cut, typing and paste over it); Backspace after a layout and Delete before one move the caret into it and join nothing. |
| - M5: History's diff leaves fences out, so it draws a layout's blocks one after another, marked, with no stray boxes (C5). |
| @@ -779,4 +779,5 @@ Fable found every round-1 finding answered in substance, and five mediums and si |
| - M7: COL13 GETs the forms and checks each carries the grammar, and posts Make team page without it: refused, draft kept. |
| - 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. |
diff --git a/editor/columns.test.mjs b/editor/columns.test.mjs| index abf5748..5a5a067 100644 |
| --- a/editor/columns.test.mjs |
| +++ b/editor/columns.test.mjs |
| @@ -217,3 +217,25 @@ test('copying inside one column puts no fence on the clipboard (M2)', () => { |
| const { text } = copyData(view.state, fidelity, from, from + 4) |
| assert.equal(text, 'Left') |
| }) |
| + |
| +test('typing goes on in the column after a structural reparse (round 2)', () => { |
| + const body = ':::: columns\n\n::: column\nAlpha.\n\nSecond.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::' |
| + 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())) |
| + 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) |
| +}) |
| + |
| +test('a structural reparse in a column leaves code as it was (round 2)', () => { |
| + const body = ':::: columns\n\n::: column\n```\n:::\nkeep\n```\n\nText.\n\n:::\n\n' + |
| + '::: column\nB.\n\n:::\n\n::::' |
| + const { view, fidelity } = editor(body) |
| + const pos = textPos(view, 'Text') + 'Text.'.length |
| + view.dispatch(view.state.tr.insert(pos, view.state.schema.nodes.hard_break.create())) |
| + view.dispatch(view.state.tr.insertText('- x', pos + 1)) |
| + const out = saved(view, fidelity) |
| + assert.match(out, /```\n:::\nkeep\n```/u, JSON.stringify(out)) |
| +}) |
diff --git a/editor/fidelity.mjs b/editor/fidelity.mjs| index 656f48e..cfdf1c4 100644 |
| --- a/editor/fidelity.mjs |
| +++ b/editor/fidelity.mjs |
| @@ -19,7 +19,9 @@ |
| import { Plugin, PluginKey, TextSelection } from 'prosemirror-state' |
| import { Fragment } from 'prosemirror-model' |
| -import { parse, normalise, cleanBody, Item, Quote, Code, Rule, isFence, isFenceLike } from './markup.mjs' |
| +import { |
| + parse, normalise, cleanBody, Item, Quote, Code, Rule, isFence, isFenceLike, fenceOf, closesFence |
| +} from './markup.mjs' |
| import { fromBlocks } from './fromMarkdown.mjs' |
| import { |
| docBlocks, contextKey, bareNode, sameNode, serialise, serialiseBlock, |
| @@ -633,11 +635,37 @@ function adoptColumn (tr, fidelity, block) { |
| if (depth === 0) return |
| const column = $at.node(depth) |
| const start = $at.before(depth) + 1 |
| + const end = start + column.content.size |
| const schema = tr.doc.type.schema |
| const own = schema.topNodeType.create(null, column.content) |
| - const text = serialiseDetailed(own, null, { edges: false, raw: true }).body |
| - .replace(/^([ \t]*):::/gmu, '$1\u200b:::') |
| + 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()) |
| - tr.replaceWith(start, start + column.content.size, content) |
| + // 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)) |
| + } |
| +} |
| + |
| +// neutralLines puts U+200B before the first ":" of every fence-like |
| +// line of text, never inside code (§1.7 rule 1). |
| +function neutralLines (text) { |
| + let fence = null |
| + return text.split('\n').map(line => { |
| + if (fence) { |
| + if (closesFence(line, fence)) fence = null |
| + return line |
| + } |
| + const opened = fenceOf(line) |
| + if (opened) { |
| + fence = opened |
| + return line |
| + } |
| + return isFenceLike(line) ? line.replace(/^([ \t]*):::/u, '$1\u200b:::') : line |
| + }).join('\n') |
| } |
diff --git a/editor/serialize.mjs b/editor/serialize.mjs| index 73c5f5b..5dea200 100644 |
| --- a/editor/serialize.mjs |
| +++ b/editor/serialize.mjs |
| @@ -275,20 +275,10 @@ function quoteText (block) { |
| function codeText (node, last) { |
| const attrs = node.attrs |
| - let open = /^ {0,3}(?:`{3,}|~{3,})$/u.test(attrs.fence ?? '') ? attrs.fence : '```' |
| - // A line of the code that would close the fence early makes the fence |
| - // longer, so the code stays code and nothing after it is swallowed: |
| - // inside a column, the column's closer (Fable on the build, H2). |
| - const lines = node.textContent.split('\n') |
| - let lengthened = false |
| - while (lines.some(line => line.replace(/^ +/u, '').startsWith(open.trimStart()))) { |
| - open += open.trimStart()[0] |
| - lengthened = true |
| - } |
| + const open = /^ {0,3}(?:`{3,}|~{3,})$/u.test(attrs.fence ?? '') ? attrs.fence : '```' |
| let out = open + String(attrs.info ?? '').split('\n')[0] |
| if (node.textContent !== '') out += '\n' + node.textContent |
| - if (lengthened) out += '\n' + open.trimStart() |
| - else if (attrs.close != null && isFenceLine(attrs.close)) out += '\n' + attrs.close |
| + if (attrs.close != null && isFenceLine(attrs.close)) out += '\n' + attrs.close |
| if (!last && !fenceClosed(out)) out += '\n' + open.trimStart() |
| return out |
| } |
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json| index 9187f88..3a4af9f 100644 |
| --- a/internal/mapa/markup/testdata/editor.json |
| +++ b/internal/mapa/markup/testdata/editor.json |
| @@ -10,9 +10,9 @@ |
| {"name":"edge/bullet-kinds","body":"[[2026-11-12]]\n*a*\n\n[[2026-11-12]]\n[[2026-11-12]]a\n\n**b**\n - c\n*n~~~ot a bullnot","blocks":["paragraph","paragraph","paragraph","item:bullet_list:0:true"]}, |
| {"name":"edge/tasks","body":"\ud83d\ud83d\udc4b\udc4b\n\n\ud83d\ud83d\udc4b\udc4b","blocks":["paragraph","paragraph"]}, |
| {"name":"edge/unclosed-fence","body":"```js\nlet a a = 1\n\nm\n```\n\n[[Halden Robotics]]-","blocks":["code","paragraph"]}, |
| -{"name":"edge/tilde-fences","body":"~~~~\n[x](https://x.y) ^ab\n~~~\n\n~~~~\n\udc4b ^a","blocks":["code","code"]}, |
| +{"name":"edge/tilde-fences","body":"~~~\n[x](https://x.y) ^ab\n~~~\n\n~~~\n\udc4b ^a","blocks":["code","code"]}, |
| {"name":"edge/fence-other-kind-unclosed","body":"~~~\n\n\n~~~\n\n~~~\n`````\n~~~\n\n```\n```\n\n[[Acme#^b1|that]]\n\n```\n`\n```\n\n```\n```\n\nword [[Halden Robotics]]","blocks":["code","code","code","paragraph","code","code","paragraph"]}, |
| -{"name":"edge/fence-indented-close","body":"````\nx\n \n ```\n\n````\n \n ```\n\n````\naft\n````\n\n````\nre","blocks":["code","code","code","code"]}, |
| +{"name":"edge/fence-indented-close","body":"```\nx\n ```w ``\n\n```\nord \n```\n\na*r*","blocks":["code","code","paragraph"]}, |
| {"name":"edge/fence-blank-last-line","body":"[x](https://x.y)","blocks":["paragraph"]}, |
| {"name":"edge/fence-empty","body":"~~~![[fichas:c1]]\n\n\n~~~\n\n","blocks":["code","paragraph"]}, |
| {"name":"edge/fence-alone","body":"","blocks":[]}, |
| @@ -221,7 +221,7 @@ |
| {"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\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/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/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"]}, |
| @@ -378,7 +378,7 @@ |
| {"name":"commonmark/134","body":" ``![a w`\n aa[[Acme]]a\n ``*`*","blocks":["paragraph"]}, |
| {"name":"commonmark/135","body":"```\nworor\n ```","blocks":["code"]}, |
| {"name":"commonmark/136","body":"****\n\n\n","blocks":["rule","paragraph"]}, |
| -{"name":"commonmark/137","body":"````\n**\n````\n\n````\na- \n````\n\n- [[2026-11-12]]\n\n[[2026-11-12]]","blocks":["code","code","item:bullet_list:0:true","paragraph"]}, |
| +{"name":"commonmark/137","body":"```\n**\n```\n\n```\na- \n```\n\n- [[2026-11-12]]\n\n[[2026-11-12]]","blocks":["code","code","item:bullet_list:0:true","paragraph"]}, |
| {"name":"commonmark/138","body":"``` ```\naaaé","blocks":["code"]}, |
| {"name":"commonmark/139","body":"~~~~~~\n[\n~~~ ~~\n\n![[fichas:c1]]x](http1. **s://x.yoword \n\n![[fichas:c1]] ^ab","blocks":["code","paragraph","paragraph"]}, |
| {"name":"commonmark/140","body":"foob\n\naré\n\n[x](https://x.y)f\noz[[Acme]]","blocks":["paragraph","paragraph","paragraph"]}, |
| @@ -414,7 +414,7 @@ |
| {"name":"commonmark/170","body":"<script type = \"Hello JavaSc1. ript!\";\n</script>\nokay---\n\nte|xt/ javascript\">\n// JavaScript exampledocume```nt.getElempt>\nokay\n\ntex- t/javascript\">\n// Ja\n\nvaScript example\n\ndocument.getElementById(\"demo\").innerHTML = \"Hello JavaScript!\";\n</script>\nokay","blocks":["paragraph","paragraph","paragraph","paragraph","paragraph"]}, |
| {"name":"commonmark/171","body":"<**[ ]** \n\n_bar_`\n\n***fo***\n\n![[fichas:c1]]*o*\n\nt\nextarbar_\n\n</textarea>\n\n</textar\nea>","blocks":["paragraph","paragraph","paragraph","paragraph","paragraph","paragraph","paragraph"]}, |
| {"name":"commonmark/172","body":"<style\n type=\"tex\nt/css\">\nh1 {color:red;}p {c ^abolor:blue;}\n</style>\nokay<style\n type=\"~~~te[x](https://x.y)x\nt/css\">\nh1 {color:re`![[fichas:c1]]``d;}p {c ^abolor:blue;}\n</style>\nokay","blocks":["paragraph"]}, |
| -{"name":"commonmark/173","body":"<style\n to\">\n\n````f[[Acme#^b1|that]]oé[[Acme#^b1|that]] ^ab\n```\n````\n\n---","blocks":["paragraph","code","code"]}, |
| +{"name":"commonmark/173","body":"<style\n to\">\n\n```f[[Acme#^b1|that]]oé[[Acme#^b1|that]] ^ab\n```\n```\n\n---","blocks":["paragraph","code","code"]}, |
| {"name":"commonmark/174","body":"> [[2026-11-12]]<d\n\n```*\n```\n\nwa*rd*","blocks":["quote","code","paragraph"]}, |
| {"name":"commonmark/175","body":"*--->*\n\n- [ ] 1. foo\n- [ ] 1. foo\n\n`","blocks":["paragraph","item:bullet_list:0:true","item:bullet_list:0:false","paragraph"]}, |
| {"name":"commonmark/176","body":"<s[ ] ```tyleor:reeor:re\n\n![[fichas:c1]]d;}</|>p{yle>d;}</>p{yle>\n*foo*","blocks":["paragraph","paragraph"]}, |