{"draft":null,"from":161,"to":318,"files":[{"path":"src/engine/experimental/projection-reader.ts","added":85,"removed":6,"diff":"--- a/src/engine/experimental/projection-reader.ts\n+++ b/src/engine/experimental/projection-reader.ts\n@@ -1,6 +1,5 @@\n import { startNode } from \"../keys.ts\";\n import { StableSet } from \"../state-source.ts\";\n-import { joinLines } from \"../text.ts\";\n import type { FileAttrs, ReadView, SeqLine, VisibleLine } from \"../view.ts\";\n import type { ExperimentalMarkerProjection, MarkerState } from \"./projection-marker.ts\";\n \n@@ -74,7 +73,14 @@\n \t}\n \tlineNumber(path: string, line: string): number {\n \t\tthis.#assertLive();\n-\t\treturn this.lines(path).findIndex((item) => item.id === line);\n+\t\tlet index = 0;\n+\t\tfor (const id of this.#adapter.lineIds(this.#state, path)) {\n+\t\t\tthis.#assertLive();\n+\t\t\tif (id === line) return index;\n+\t\t\tindex++;\n+\t\t}\n+\t\tthis.#assertLive();\n+\t\treturn -1;\n \t}\n \tsameText(path: string, other: ReadView): boolean {\n \t\tthis.#assertLive();\n@@ -104,6 +110,30 @@\n \t\tfor (const id of this.graph.movers()) if (this.set.has(id)) return true;\n \t\treturn false;\n \t}\n+\t*#textChunks(n: number): IterableIterator<string> {\n+\t\tthis.#assertLive();\n+\t\tconst iterator = this.graph.textChunks(n);\n+\t\twhile (true) {\n+\t\t\tthis.#assertLive();\n+\t\t\tconst next = iterator.next();\n+\t\t\tthis.#assertLive();\n+\t\t\tif (next.done) return;\n+\t\t\tyield next.value;\n+\t\t}\n+\t}\n+\t*lineChunks(path: string): IterableIterator<() => Iterable<string>> {\n+\t\tthis.#assertLive();\n+\t\tconst iterator = this.#adapter.lineIds(this.#state, path);\n+\t\twhile (true) {\n+\t\t\tthis.#assertLive();\n+\t\t\tconst next = iterator.next();\n+\t\t\tthis.#assertLive();\n+\t\t\tif (next.done) return;\n+\t\t\tconst n = this.graph.lineN(next.value);\n+\t\t\tyield () => this.#textChunks(n);\n+\t\t}\n+\t}\n+\n \t*visibleLines(path: string): IterableIterator<VisibleLine> {\n \t\tthis.#assertLive();\n \t\tconst graph = this.#adapter.graph;\n@@ -122,6 +152,34 @@\n \t\tthis.#assertLive();\n \t\treturn [...this.visibleLines(path)];\n \t}\n+\t*#buildingLines(path: string): IterableIterator<VisibleLine> {\n+\t\tthis.#assertLive();\n+\t\tconst graph = this.#adapter.graph;\n+\t\tconst iterator = this.#adapter.lineIds(this.#state, path);\n+\t\twhile (true) {\n+\t\t\tthis.#assertLive();\n+\t\t\tconst next = iterator.next();\n+\t\t\tthis.#assertLive();\n+\t\t\tif (next.done) return;\n+\t\t\tconst id = next.value;\n+\t\t\tconst n = graph.lineN(id);\n+\t\t\tconst assertLive = () => this.#assertLive();\n+\t\t\tyield {\n+\t\t\t\tid,\n+\t\t\t\ttextChunks: () => this.#textChunks(n),\n+\t\t\t\tget text() {\n+\t\t\t\t\tassertLive();\n+\t\t\t\t\treturn graph.textOf(n);\n+\t\t\t\t},\n+\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),\n+\t\t\t};\n+\t\t}\n+\t}\n+\tbuildLines(path: string): readonly VisibleLine[] {\n+\t\tthis.#assertLive();\n+\t\treturn [...this.#buildingLines(path)];\n+\t}\n+\n \tsequence(path: string): readonly SeqLine[] {\n \t\tthis.#assertLive();\n \t\tconst adapter = this.#adapter,\n@@ -175,13 +233,34 @@\n \tfileOf(line: string): string {\n \t\tthis.#assertLive();\n \t\tif (line.startsWith(\"^\")) return line.slice(1);\n-\t\tconst marker = this.#adapter.markers.get(this.#state.locator, this.graph.lineN(line) + 1);\n-\t\tif (marker?.kind !== \"line\") throw Error(\"missing projected line\");\n-\t\treturn this.#adapter.sequence.fileAt(this.#state.sequence, marker.enter);\n+\t\tlet current = line;\n+\t\twhile (!current.startsWith(\"^\")) {\n+\t\t\tconst n = this.graph.lineN(current);\n+\t\t\tif (n < 0) throw Error(\"unknown projected line\");\n+\t\t\tconst marker = this.#adapter.markers.get(this.#state.locator, n + 1);\n+\t\t\tif (marker?.kind === \"line\") return this.#adapter.sequence.fileAt(this.#state.sequence, marker.enter);\n+\t\t\t// A line written outside this view has no marker. Follow canonical ancestry\n+\t\t\t// until it reaches a line whose placement this view actually contains.\n+\t\t\tif (marker || this.#adapter.members.get(this.#state.membership, this.graph.writerSeqOf(n))?.present)\n+\t\t\t\tthrow Error(\"missing projected line\");\n+\t\t\tconst parent = this.graph.lineParent(current);\n+\t\t\tif (parent === undefined) throw Error(\"missing projected line parent\");\n+\t\t\tcurrent = parent;\n+\t\t}\n+\t\treturn current.slice(1);\n \t}\n \ttext(path: string): string {\n \t\tthis.#assertLive();\n-\t\treturn joinLines([...this.visibleLines(path)].map((line) => line.text));\n+\t\tlet text = \"\",\n+\t\t\tpart = \"\";\n+\t\tfor (const line of this.visibleLines(path)) {\n+\t\t\tpart += `${line.text}\\n`;\n+\t\t\tif (part.length >= 16384) {\n+\t\t\t\ttext += part;\n+\t\t\t\tpart = \"\";\n+\t\t\t}\n+\t\t}\n+\t\treturn text + part;\n \t}\n \thasFile(path: string): boolean {\n \t\tthis.#assertLive();"}],"unmatched":[]}