Lines 1–5 at 318 (were 1–6 at 162)
11import { startNode } from "../keys.ts"; 22import { StableSet } from "../state-source.ts"; 3−import { joinLines } from "../text.ts";
43import type { FileAttrs, ReadView, SeqLine, VisibleLine } from "../view.ts"; 54import type { ExperimentalMarkerProjection, MarkerState } from "./projection-marker.ts"; Lines 73–86 at 318 (were 74–80 at 162)
7574 lineNumber(path: string, line: string): number { 77− return this.lines(path).findIndex((item) => item.id === line);
77+ for (const id of this.#adapter.lineIds(this.#state, path)) { 79+ if (id === line) return index; 7985 sameText(path: string, other: ReadView): boolean { Lines 110–139 at 318 (were 104–109 at 162)
104110 for (const id of this.graph.movers()) if (this.set.has(id)) return true; 113+ *#textChunks(n: number): IterableIterator<string> { 115+ const iterator = this.graph.textChunks(n); 118+ const next = iterator.next(); 120+ if (next.done) return; 124+ *lineChunks(path: string): IterableIterator<() => Iterable<string>> { 126+ const iterator = this.#adapter.lineIds(this.#state, path); 129+ const next = iterator.next(); 131+ if (next.done) return; 132+ const n = this.graph.lineN(next.value); 133+ yield () => this.#textChunks(n); 107137 *visibleLines(path: string): IterableIterator<VisibleLine> { 108138 this.#assertLive(); 109139 const graph = this.#adapter.graph; Lines 152–185 at 318 (were 122–127 at 162)
122152 this.#assertLive(); 123153 return [...this.visibleLines(path)]; 155+ *#buildingLines(path: string): IterableIterator<VisibleLine> { 157+ const graph = this.#adapter.graph; 158+ const iterator = this.#adapter.lineIds(this.#state, path); 161+ const next = iterator.next(); 163+ if (next.done) return; 164+ const id = next.value; 165+ const n = graph.lineN(id); 166+ const assertLive = () => this.#assertLive(); 169+ textChunks: () => this.#textChunks(n), 172+ return graph.textOf(n); 174+ atom: graph.idOfSeq(graph.writerSeqOf(n)), 178+ buildLines(path: string): readonly VisibleLine[] { 180+ return [...this.#buildingLines(path)]; 125183 sequence(path: string): readonly SeqLine[] { 126184 this.#assertLive(); 127185 const adapter = this.#adapter, Lines 233–266 at 318 (were 175–187 at 162)
175233 fileOf(line: string): string { 176234 this.#assertLive(); 177235 if (line.startsWith("^")) return line.slice(1); 178− const marker = this.#adapter.markers.get(this.#state.locator, this.graph.lineN(line) + 1);
179− if (marker?.kind !== "line") throw Error("missing projected line");
180− return this.#adapter.sequence.fileAt(this.#state.sequence, marker.enter);
237+ while (!current.startsWith("^")) { 238+ const n = this.graph.lineN(current); 239+ if (n < 0) throw Error("unknown projected line"); 240+ const marker = this.#adapter.markers.get(this.#state.locator, n + 1); 241+ if (marker?.kind === "line") return this.#adapter.sequence.fileAt(this.#state.sequence, marker.enter); 242+ // A line written outside this view has no marker. Follow canonical ancestry 243+ // until it reaches a line whose placement this view actually contains. 244+ if (marker || this.#adapter.members.get(this.#state.membership, this.graph.writerSeqOf(n))?.present) 245+ throw Error("missing projected line"); 246+ const parent = this.graph.lineParent(current); 247+ if (parent === undefined) throw Error("missing projected line parent"); 250+ return current.slice(1); 182252 text(path: string): string { 183253 this.#assertLive(); 184− return joinLines([...this.visibleLines(path)].map((line) => line.text));
256+ for (const line of this.visibleLines(path)) { 257+ part += `${line.text}\n`; 258+ if (part.length >= 16384) { 186265 hasFile(path: string): boolean { 187266 this.#assertLive();