Skip to content

Commit 3bf52b9

Browse files
committed
refactor(json-crdt-extensions): 💡 rename internal overlay methods
1 parent 9372a47 commit 3bf52b9

File tree

1 file changed

+17
-13
lines changed
  • src/json-crdt-extensions/peritext/overlay

1 file changed

+17
-13
lines changed

src/json-crdt-extensions/peritext/overlay/Overlay.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ import type {Printable} from 'tree-dump/lib/types';
1717
import type {MutableSlice, Slice} from '../slice/types';
1818
import type {Slices} from '../slice/Slices';
1919

20+
/**
21+
* Overlay is a tree structure that represents all the intersections of slices
22+
* in the text. It is used to quickly find all the slices that overlap a
23+
* given point in the text. The overlay is a read-only structure, its state
24+
* is changed only by calling the `refresh` method, which updates the overlay
25+
* based on the current state of the text and slices.
26+
*/
2027
export class Overlay implements Printable, Stateful {
2128
public root: OverlayPoint | undefined = undefined;
2229

2330
constructor(protected readonly txt: Peritext) {}
2431

25-
/**
26-
* @todo Rename to .point().
27-
*/
28-
protected overlayPoint(id: ITimestampStruct, anchor: Anchor): OverlayPoint {
29-
return new OverlayPoint(this.txt.str, id, anchor);
30-
}
31-
32-
protected markerPoint(marker: MarkerSlice, anchor: Anchor): OverlayPoint {
33-
return new MarkerOverlayPoint(this.txt.str, marker.start.id, anchor, marker);
34-
}
35-
3632
public first(): OverlayPoint | undefined {
3733
return this.root ? first(this.root) : undefined;
3834
}
@@ -136,12 +132,20 @@ export class Overlay implements Printable, Stateful {
136132
return state;
137133
}
138134

135+
private point(id: ITimestampStruct, anchor: Anchor): OverlayPoint {
136+
return new OverlayPoint(this.txt.str, id, anchor);
137+
}
138+
139+
private mPoint(marker: MarkerSlice, anchor: Anchor): MarkerOverlayPoint {
140+
return new MarkerOverlayPoint(this.txt.str, marker.start.id, anchor, marker);
141+
}
142+
139143
/**
140144
* Retrieve an existing {@link OverlayPoint} or create a new one, inserted
141145
* in the tree, sorted by spatial dimension.
142146
*/
143147
private upsertPoint(point: Point): [point: OverlayPoint, isNew: boolean] {
144-
const newPoint = this.overlayPoint(point.id, point.anchor);
148+
const newPoint = this.point(point.id, point.anchor);
145149
const pivot = this.insPoint(newPoint);
146150
if (pivot) return [pivot, false];
147151
return [newPoint, true];
@@ -173,7 +177,7 @@ export class Overlay implements Printable, Stateful {
173177
}
174178

175179
private insMarker(slice: MarkerSlice): [start: OverlayPoint, end: OverlayPoint] {
176-
const point = this.markerPoint(slice, Anchor.Before);
180+
const point = this.mPoint(slice, Anchor.Before);
177181
const pivot = this.insPoint(point);
178182
if (!pivot) {
179183
point.refs.push(slice);

0 commit comments

Comments
 (0)