Lines 1–5 at 318 (were 1–6 at 151)
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 22–52 at 318 (were 23–40 at 151)
2322 get set(): ReadonlySet<string> { 2524 const has = (id: string) => 26− this.graph.has(id) &&
27− (this.#adapter.members.get(this.#state.membership, this.graph.atom(id).seq)?.present ?? false);
25+ this.graph.has(id) && (this.#adapter.members.get(this.#state.membership, Number(id.slice(1)))?.present ?? false); 2826 const assertLive = this.#assertLive; 27+ const members = this.#adapter.members; 28+ const root = this.#state.membership; 29+ const graph = this.graph; 2930 return new (class extends StableSet<string> { 3031 readonly retainedBytes = 64; 3132 has(id: string): boolean { 35− values(): SetIterator<string> {
36+ *values(): SetIterator<string> { 37− throw Error("unsupported projected membership enumeration");
38+ const iterator = members.entries(root); 42+ const item = iterator.next(); 43+ if (item.done) return; 44+ const [seq, member] = item.value; 45+ if (member.present) yield graph.idOfSeq(seq); Lines 73–86 at 318 (were 61–67 at 151)
6274 lineNumber(path: string, line: string): number { 64− 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; 6685 sameText(path: string, other: ReadView): boolean { Lines 110–139 at 318 (were 91–96 at 151)
91110 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); 94137 *visibleLines(path: string): IterableIterator<VisibleLine> { 95138 this.#assertLive(); 96139 const graph = this.#adapter.graph; Lines 152–185 at 318 (were 109–114 at 151)
109152 this.#assertLive(); 110153 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)]; 112183 sequence(path: string): readonly SeqLine[] { 113184 this.#assertLive(); 114185 const adapter = this.#adapter, Lines 233–266 at 318 (were 162–174 at 151)
162233 fileOf(line: string): string { 163234 this.#assertLive(); 164235 if (line.startsWith("^")) return line.slice(1); 165− const marker = this.#adapter.markers.get(this.#state.locator, this.graph.lineN(line) + 1);
166− if (marker?.kind !== "line") throw Error("missing projected line");
167− 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); 169252 text(path: string): string { 170253 this.#assertLive(); 171− 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) { 173265 hasFile(path: string): boolean { 174266 this.#assertLive();