Skip to content

Commit

Permalink
feat(json-crdt-extensions): 🎸 add ability to start iteration includin…
Browse files Browse the repository at this point in the history
…g the first point
  • Loading branch information
streamich committed Nov 6, 2024
1 parent 1045d77 commit 33d8539
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/json-crdt-extensions/peritext/overlay/Overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ export class Overlay<T = string> implements Printable, Stateful {
}) as Chunk<T>;
}

public points0(after: undefined | OverlayPoint<T>): UndefIterator<OverlayPoint<T>> {
let curr = after ? next(after) : this.first();
public points0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndefIterator<OverlayPoint<T>> {
let curr = after ? (inclusive ? after : next(after)) : this.first();
return () => {
const ret = curr;
if (curr) curr = next(curr);
return ret;
};
}

public points(after?: undefined | OverlayPoint<T>): IterableIterator<OverlayPoint<T>> {
return new UndefEndIter(this.points0(after));
public points(after?: undefined | OverlayPoint<T>, inclusive?: boolean): IterableIterator<OverlayPoint<T>> {
return new UndefEndIter(this.points0(after, inclusive));
}

public markers0(after: undefined | MarkerOverlayPoint<T>): UndefIterator<MarkerOverlayPoint<T>> {
Expand Down Expand Up @@ -325,7 +325,7 @@ export class Overlay<T = string> implements Printable, Stateful {
public stat(range: Range<T>, endOnMarker = 10): [complete: Set<SliceType>, partial: Set<SliceType>, markerCount: number] {
const {start, end} = range;
const after = this.getOrNextLower(start); // TODO: this should consider only non-marker points.
const iterator = this.points0(after ? prev(after) : void 0);
const iterator = this.points0(after, true);
const partial = new Set<SliceType>();
let complete: Set<SliceType> = new Set();
let isFirst = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const statTestSuite = (setup: () => Kit) => {
const stats = peritext.overlay.stat(editor.cursor);
expect(stats).toEqual([new Set(['bold']), new Set(), 0]);
});

test.todo('multiple interleaved styles');
test.todo('erasures work');
test.todo('handle stack slices');
test.todo('Edge case: text REL end');
test.todo('Edge case: text ABS end');
test.todo('Edge case: marker overlay point is the first point');
test.todo('handle markers in between: can terminate early once first marker encountered');
};

describe('.stat()', () => {
Expand Down

0 comments on commit 33d8539

Please sign in to comment.