{"draft":null,"from":220,"to":221,"files":[{"path":"src/engine/graph.ts","added":39,"removed":7,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -262,6 +262,8 @@\n export type PackedDelete = [number, number];\n /** An attribute set on a file: [seq, name, value]. */\n export type PackedAttr = [number, string, string | null];\n+/** A run written in another file under one of a file's lines: [the parent's n, the run's file index]. */\n+export type PackedCrossing = [number, number];\n const EMPTY_NUMBERS: readonly number[] = Object.freeze([]);\n /** Lines longer than this aren't packed with their file; their text is read on its own. */\n const PACKED_TEXT = 4096;\n@@ -599,13 +601,16 @@\n \t\t\tthis.#fileTexts = storedLists<string | null>(storage, \"file-texts\");\n \t\t\tthis.#fileDeletes = storedLists<PackedDelete>(storage, \"file-deletes\");\n \t\t\tthis.#fileAttrs = storedLists<PackedAttr>(storage, \"file-attrs\");\n+\t\t\tthis.#fileCrossings = storedLists<PackedCrossing>(storage, \"file-crossings\");\n \t\t\tthis.#packFiles = options.packFiles ?? true;\n \t\t}\n \t}\n \n \t// Each file's line history packed, in pages (abso Capacity) ---------------------------------------------------\n \t// For each file, by its path index: every line written in it ([n, parent code, writer seq, k, replaces]) and its\n-\t// text, every delete of one of those lines ([n, deleter seq]), and every attribute set on it ([seq, name, value]).\n+\t// text, every delete of one of those lines ([n, deleter seq]), every attribute set on it ([seq, name, value]), and\n+\t// every run written in another file under one of its lines ([parent n, the run's file]): a line follows its parent,\n+\t// so a run written while its parent was moved elsewhere lays out wherever the parent is.\n \t// Appended as atoms are added, so a view lays a file out from a few pages instead of a row read per line. Kept from\n \t// a fresh adoption on; a graph adopted before has none, and views lay out as before.\n \n@@ -613,19 +618,39 @@\n \t#fileTexts: ReturnType<typeof storedLists<string | null>> | undefined;\n \t#fileDeletes: ReturnType<typeof storedLists<PackedDelete>> | undefined;\n \t#fileAttrs: ReturnType<typeof storedLists<PackedAttr>> | undefined;\n+\t#fileCrossings: ReturnType<typeof storedLists<PackedCrossing>> | undefined;\n \t/** Whether a new stored graph starts packing (GraphOptions.packFiles). */\n \t#packFiles = true;\n-\t/** Whether this graph's files are packed: read once, when first asked, so opening reads nothing. */\n-\t#packedKnown: boolean | undefined;\n+\t/**\n+\t * How this graph's files are packed, read once when first asked so opening reads nothing: 0 not at all, 1 lines,\n+\t * deletes and attributes, 2 the runs written across files as well.\n+\t */\n+\t#formatKnown: number | undefined;\n+\tget #format(): number {\n+\t\tif (this.#formatKnown === undefined) {\n+\t\t\tconst format = this.#storage?.read(\"file-lines:meta\", \"format\");\n+\t\t\tthis.#formatKnown = format === 1 || format === 2 ? format : 0;\n+\t\t}\n+\t\treturn this.#formatKnown;\n+\t}\n \tget #packed(): boolean {\n-\t\tthis.#packedKnown ??= !!this.#storage && this.#storage.read(\"file-lines:meta\", \"format\") === 1;\n-\t\treturn this.#packedKnown;\n+\t\treturn this.#format >= 1;\n \t}\n+\tget #crossings(): boolean {\n+\t\treturn this.#format >= 2;\n+\t}\n \n \t/** Whether this graph keeps each file's line history packed. */\n \tget packedFiles(): boolean {\n \t\treturn this.#packed;\n \t}\n+\t/**\n+\t * Whether a file can be laid out from packed history alone: it also keeps the runs written across files. A graph\n+\t * packed before those were kept lays files out line by line.\n+\t */\n+\tget packedLayout(): boolean {\n+\t\treturn this.#crossings;\n+\t}\n \t/** A path's index, or undefined when nothing was ever written or set in it. */\n \tpathIndexOf(path: string): number | undefined {\n \t\treturn this.#pathIndex.get(path);\n@@ -646,6 +671,9 @@\n \t*packedAttrs(file: number): IterableIterator<PackedAttr> {\n \t\tyield* this.#fileAttrs!.values(String(file));\n \t}\n+\t*packedCrossings(file: number): IterableIterator<PackedCrossing> {\n+\t\tyield* this.#fileCrossings!.values(String(file));\n+\t}\n \n \t/** Where an atom's key and delete lists are when the graph doesn't keep them (#46): the stored atom. */\n \t#lists: ((seq: number) => AtomLists) | undefined;\n@@ -1449,8 +1477,8 @@\n \t\t\tthis.#storage.write(\"ordered-children\", \"format\", 2);\n \t\t}\n \t\tif (this.#storage && this.#atoms.length === 0 && this.#packFiles) {\n-\t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 1);\n-\t\t\tthis.#packedKnown = true;\n+\t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 2);\n+\t\t\tthis.#formatKnown = 2;\n \t\t}\n \n \t\tif (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));\n@@ -1535,6 +1563,10 @@\n \t\t\telse pushOne(this.#runStarts, parent, first);\n \t\t\tconst replacesParent = deletes(run.parent) ? 1 : 0;\n \t\t\tif (this.#packed) {\n+\t\t\t\tif (this.#crossings && parent >= 0) {\n+\t\t\t\t\tconst from = this.#lineFile.at(parent);\n+\t\t\t\t\tif (from !== file) this.#fileCrossings!.append(String(from), [parent, file]);\n+\t\t\t\t}\n \t\t\t\tconst base = this.#lineBase[seq]!;\n \t\t\t\tthis.#fileLines!.appendAll(\n \t\t\t\t\tString(file),"}],"unmatched":[]}