Skip to content

Commit dc982cd

Browse files
committed
feat(json-crdt-extensions): 🎸 support left char retrieval for deleted points
1 parent f794696 commit dc982cd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

‎src/json-crdt-extensions/peritext/point/Point.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ export class Point implements Pick<Stateful, 'refresh'>, Printable {
195195

196196
public leftChar(): ChunkSlice | undefined {
197197
let chunk = this.chunk();
198-
if (!chunk || chunk.del) return;
198+
if (!chunk) return;
199+
if (chunk.del) {
200+
const prevId = this.prevId();
201+
if (!prevId) return;
202+
const tmp = new Point(this.txt, prevId, Anchor.After);
203+
return tmp.leftChar();
204+
}
199205
if (this.anchor === Anchor.After) {
200206
const off = this.id.time - chunk.id.time;
201207
return new ChunkSlice(chunk, off, 1);

‎src/json-crdt-extensions/peritext/point/__tests__/Point.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ describe('.rightChar()', () => {
551551
const end = peritext.pointAt(res.length - 1, Anchor.After);
552552
expect(end.rightChar()).toBe(undefined);
553553
});
554+
555+
test('retrieves left char of a deleted point', () => {
556+
const {peritext, chunkD1} = setupWithChunkedText();
557+
const p1 = peritext.point(chunkD1.id, Anchor.Before);
558+
expect(p1.leftChar()!.view()).toBe('3');
559+
const p2 = peritext.point(chunkD1.id, Anchor.After);
560+
expect(p2.leftChar()!.view()).toBe('3');
561+
});
554562
});
555563

556564
describe('.leftChar()', () => {

0 commit comments

Comments
 (0)