{"draft":null,"from":131,"to":132,"files":[{"path":"src/engine/view.ts","added":27,"removed":1,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -11,6 +11,7 @@\n \n import type { Graph, RelocationInfo } from \"./graph.ts\";\n import { isStartNode } from \"./keys.ts\";\n+import { resolveScratchMoves, scratchLayoutNodes } from \"./relocation-scratch.ts\";\n import { StableSet } from \"./state-source.ts\";\n import { joinLines } from \"./text.ts\";\n import { type AtomId, type AtomSet, EngineError, type LineId, type NodeId } from \"./types.ts\";\n@@ -264,6 +265,11 @@\n \n \t/** The node a line hangs off in this set: where it was written, or where a move put it. */\n \tparentOf(line: LineId): NodeId {\n+\t\tif (this.graph.lineParent(line) === undefined) throw new EngineError(\"unknown-line\", `no line ${line}`);\n+\t\tif (this.#hasMoves && this.graph.hasOrderedChildren)\n+\t\t\treturn this.graph.withProjectionScratch((scratch) =>\n+\t\t\t\tresolveScratchMoves(this.graph, (id) => this.#has(this.graph.atom(id).seq), scratch).parent(line),\n+\t\t\t);\n \t\tconst r = this.#hasMoves ? this.#relocations().get(line) : undefined;\n \t\tif (r) return r.parent;\n \t\tconst parent = this.graph.lineParent(line);\n@@ -290,6 +296,13 @@\n \t#fileOfN(n: number): string {\n \t\tconst graph = this.graph;\n \t\tif (!this.#hasMoves) return graph.writtenIn(n);\n+\t\tif (graph.hasOrderedChildren)\n+\t\t\treturn graph.withProjectionScratch((scratch) => {\n+\t\t\t\tconst moves = resolveScratchMoves(graph, (id) => this.#has(graph.atom(id).seq), scratch);\n+\t\t\t\tlet current = graph.nodeOf(n);\n+\t\t\t\twhile (!isStartNode(current)) current = moves.parent(current);\n+\t\t\t\treturn current.slice(1);\n+\t\t\t});\n \t\tconst relocs = this.#relocationsN();\n \t\t// Keep only a fixed tail of the walk for path compression. The selected\n \t\t// relocation graph is acyclic, so traversal needs no history-sized stack.\n@@ -396,6 +409,19 @@\n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n \t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n+\t\tif (this.#hasMoves && graph.hasOrderedChildren)\n+\t\t\treturn graph.withProjectionScratch((scratch) =>\n+\t\t\t\tthis.#layoutResolved(\n+\t\t\t\t\tpath,\n+\t\t\t\t\tcomplete,\n+\t\t\t\t\tscratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, `^${path}`),\n+\t\t\t\t),\n+\t\t\t);\n+\t\treturn this.#layoutResolved(path, complete);\n+\t}\n+\n+\t#layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {\n+\t\tconst graph = this.graph;\n \t\t// For each attribute, the highest-priority setter in the set wins.\n \t\tconst setters = new Map<string, { id: AtomId; value: string | null }>();\n \t\tfor (const id of graph.eachAtomIn(path)) {\n@@ -413,7 +439,7 @@\n \n \t\tconst start = graph.startCodeOf(path);\n \t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;\n-\t\tfor (const n of start === undefined ? [] : this.#layoutNodes(start)) {\n+\t\tfor (const n of nodes ?? (start === undefined ? [] : this.#layoutNodes(start))) {\n \t\t\tlet deleted = false;\n \t\t\tconst by: number[] = [];\n \t\t\tfor (const deleter of graph.eachDeleterSeqOf(n)) {"}],"unmatched":[]}