Skip to content

Commit c529aaf

Browse files
committed
feat(json-crdt-extensions): 🎸 improve Pertiext .toString() presentation
1 parent 3bf52b9 commit c529aaf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/json-crdt-extensions/peritext/Peritext.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Model} from '../../json-crdt/model';
1313
import {CONST, updateNum} from '../../json-hash';
1414
import {SESSION} from '../../json-crdt-patch/constants';
1515
import {s} from '../../json-crdt-patch';
16+
import {ExtraSlices} from './slice/ExtraSlices';
1617
import type {ITimestampStruct} from '../../json-crdt-patch/clock';
1718
import type {Printable} from 'tree-dump/lib/types';
1819
import type {MarkerSlice} from './slice/MarkerSlice';
@@ -72,7 +73,7 @@ export class Peritext implements Printable {
7273
localSlicesModel: SlicesModel = Model.create(EXTRA_SLICES_SCHEMA, SESSION.LOCAL),
7374
) {
7475
this.savedSlices = new Slices(this.model, slices, this.str);
75-
this.extraSlices = new Slices(extraSlicesModel, extraSlicesModel.root.node().get(0)!, this.str);
76+
this.extraSlices = new ExtraSlices(extraSlicesModel, extraSlicesModel.root.node().get(0)!, this.str);
7677
const localApi = localSlicesModel.api;
7778
localApi.onLocalChange.listen(() => {
7879
localApi.flush();
@@ -249,14 +250,15 @@ export class Peritext implements Printable {
249250

250251
public toString(tab: string = ''): string {
251252
const nl = () => '';
253+
const {savedSlices, extraSlices, localSlices} = this;
252254
return (
253255
this.constructor.name +
254256
printTree(tab, [
255-
(tab) => this.editor.cursor.toString(tab),
256-
nl,
257257
(tab) => this.str.toString(tab),
258258
nl,
259-
(tab) => this.savedSlices.toString(tab),
259+
savedSlices.size() ? (tab) => savedSlices.toString(tab) : null,
260+
extraSlices.size() ? (tab) => extraSlices.toString(tab) : null,
261+
localSlices.size() ? (tab) => localSlices.toString(tab) : null,
260262
nl,
261263
(tab) => this.overlay.toString(tab),
262264
])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {Slices} from './Slices';
2+
3+
export class ExtraSlices extends Slices {}

0 commit comments

Comments
 (0)