diff --git a/src/json-crdt-extensions/peritext/point/Point.ts b/src/json-crdt-extensions/peritext/point/Point.ts index 989975027c..656f61211b 100644 --- a/src/json-crdt-extensions/peritext/point/Point.ts +++ b/src/json-crdt-extensions/peritext/point/Point.ts @@ -180,7 +180,13 @@ export class Point implements Pick, Printable { return chunk ? new ChunkSlice(chunk, 0, 1) : undefined; } let chunk = this.chunk(); - if (!chunk || chunk.del) return; + if (!chunk) return; + if (chunk.del) { + const nextId = this.nextId(); + if (!nextId) return; + const tmp = new Point(this.txt, nextId, Anchor.Before); + return tmp.rightChar(); + } if (this.anchor === Anchor.Before) { const off = this.id.time - chunk.id.time; return new ChunkSlice(chunk, off, 1); diff --git a/src/json-crdt-extensions/peritext/point/__tests__/Point.spec.ts b/src/json-crdt-extensions/peritext/point/__tests__/Point.spec.ts index da02c4fba6..55002fd87a 100644 --- a/src/json-crdt-extensions/peritext/point/__tests__/Point.spec.ts +++ b/src/json-crdt-extensions/peritext/point/__tests__/Point.spec.ts @@ -552,12 +552,16 @@ describe('.rightChar()', () => { expect(end.rightChar()).toBe(undefined); }); - test('retrieves left char of a deleted point', () => { - const {peritext, chunkD1} = setupWithChunkedText(); + test('retrieves right char of a deleted point', () => { + const {peritext, chunkD1, chunkD2} = setupWithChunkedText(); const p1 = peritext.point(chunkD1.id, Anchor.Before); - expect(p1.leftChar()!.view()).toBe('3'); + expect(p1.rightChar()!.view()).toBe('4'); const p2 = peritext.point(chunkD1.id, Anchor.After); - expect(p2.leftChar()!.view()).toBe('3'); + expect(p2.rightChar()!.view()).toBe('4'); + const p3 = peritext.point(chunkD2.id, Anchor.Before); + expect(p3.rightChar()!.view()).toBe('7'); + const p4 = peritext.point(chunkD2.id, Anchor.After); + expect(p4.rightChar()!.view()).toBe('7'); }); }); @@ -630,4 +634,16 @@ describe('.leftChar()', () => { expect(char.view()).toBe(res[i]); } }); + + test('retrieves left char of a deleted point', () => { + const {peritext, chunkD1, chunkD2} = setupWithChunkedText(); + const p1 = peritext.point(chunkD1.id, Anchor.Before); + expect(p1.leftChar()!.view()).toBe('3'); + const p2 = peritext.point(chunkD1.id, Anchor.After); + expect(p2.leftChar()!.view()).toBe('3'); + const p3 = peritext.point(chunkD2.id, Anchor.Before); + expect(p3.leftChar()!.view()).toBe('6'); + const p4 = peritext.point(chunkD2.id, Anchor.After); + expect(p4.leftChar()!.view()).toBe('6'); + }); });