Skip to content

Commit 348ab2c

Browse files
committed
feat(json-crdt): 🎸 implement string deletion undo in Log
1 parent 5905bfd commit 348ab2c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/json-crdt/log/Log.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,15 @@ export class Log<N extends JsonNode = JsonNode<any>> implements Printable {
226226
if (node) {
227227
const rga = node.v;
228228
if (rga instanceof StrNode) {
229-
for (const span of op.what) {
230-
// TODO: SPAN to view: ...
229+
let str = '';
230+
for (const span of op.what) str += rga.spanView(span).join('');
231+
let after = op.obj;
232+
const firstDelSpan = op.what[0];
233+
if (firstDelSpan) {
234+
const after2 = rga.prevId(firstDelSpan);
235+
if (after2) after = after2;
231236
}
237+
builder.insStr(op.obj, after, str);
232238
}
233239
}
234240
}

src/json-crdt/nodes/rga/AbstractRga.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,10 @@ export abstract class AbstractRga<T> {
793793
return chunk;
794794
}
795795

796+
/**
797+
* @param id ID of character to start the search from.
798+
* @returns Previous ID in the RGA sequence.
799+
*/
796800
public prevId(id: ITimestampStruct): ITimestampStruct | undefined {
797801
let chunk = this.findById(id);
798802
if (!chunk) return;

0 commit comments

Comments
 (0)