get rid of the slow implementation of plaintext stuff
since i have this project in version control now there's not really any reason to keep large block comments of defunct code around
This commit is contained in:
parent
90ab38c989
commit
0002803135
1 changed files with 0 additions and 51 deletions
|
@ -106,55 +106,4 @@ export class PlainTextORDT extends CausalTree<PlainTextOperation> {
|
|||
}
|
||||
return [s, metadata] as const;
|
||||
}
|
||||
|
||||
/* very slow, uncached:
|
||||
findOpAtTextIndex(textIndex: number): number {
|
||||
const [_string, metadata] = this.render();
|
||||
|
||||
for (const meta of metadata) {
|
||||
if (meta.start < textIndex && textIndex <= meta.end)
|
||||
return this.operations.findIndex(it => it === meta.op);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
render() {
|
||||
const s: string[] = [];
|
||||
const metadata = [];
|
||||
let length = 0;
|
||||
for (const op of this.operations) {
|
||||
if (op.type === "insert") {
|
||||
s.push(op.sequence);
|
||||
metadata.push({
|
||||
op,
|
||||
start: length,
|
||||
end: length + op.sequence.length,
|
||||
});
|
||||
length += op.sequence.length;
|
||||
}
|
||||
if (op.type === "delete") {
|
||||
if (!op.parent) continue;
|
||||
if (op.parent.type !== "insert") continue;
|
||||
|
||||
const len = op.parent.sequence.length;
|
||||
length -= len;
|
||||
|
||||
// since we expect to be tacked on close to the referenced op,
|
||||
// we can quickly seek back from current position
|
||||
// (it should only take a few iterations - usually 1)
|
||||
for (let idx = metadata.length - 1; idx >= 0; idx--) {
|
||||
const m = metadata[idx];
|
||||
m.start -= len;
|
||||
m.end -= len;
|
||||
if (m.op === op.parent) {
|
||||
s.splice(idx, 1);
|
||||
metadata.splice(idx, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [s.join(""), metadata] as const;
|
||||
} */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue