Skip to content

Commit

Permalink
feat(json-crdt-extensions): 馃幐 improve Pertiext .toString() presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 2, 2024
1 parent 3bf52b9 commit c529aaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/json-crdt-extensions/peritext/Peritext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Model} from '../../json-crdt/model';
import {CONST, updateNum} from '../../json-hash';
import {SESSION} from '../../json-crdt-patch/constants';
import {s} from '../../json-crdt-patch';
import {ExtraSlices} from './slice/ExtraSlices';
import type {ITimestampStruct} from '../../json-crdt-patch/clock';
import type {Printable} from 'tree-dump/lib/types';
import type {MarkerSlice} from './slice/MarkerSlice';
Expand Down Expand Up @@ -72,7 +73,7 @@ export class Peritext implements Printable {
localSlicesModel: SlicesModel = Model.create(EXTRA_SLICES_SCHEMA, SESSION.LOCAL),
) {
this.savedSlices = new Slices(this.model, slices, this.str);
this.extraSlices = new Slices(extraSlicesModel, extraSlicesModel.root.node().get(0)!, this.str);
this.extraSlices = new ExtraSlices(extraSlicesModel, extraSlicesModel.root.node().get(0)!, this.str);
const localApi = localSlicesModel.api;
localApi.onLocalChange.listen(() => {
localApi.flush();
Expand Down Expand Up @@ -249,14 +250,15 @@ export class Peritext implements Printable {

public toString(tab: string = ''): string {
const nl = () => '';
const {savedSlices, extraSlices, localSlices} = this;
return (
this.constructor.name +
printTree(tab, [
(tab) => this.editor.cursor.toString(tab),
nl,
(tab) => this.str.toString(tab),
nl,
(tab) => this.savedSlices.toString(tab),
savedSlices.size() ? (tab) => savedSlices.toString(tab) : null,
extraSlices.size() ? (tab) => extraSlices.toString(tab) : null,
localSlices.size() ? (tab) => localSlices.toString(tab) : null,
nl,
(tab) => this.overlay.toString(tab),
])
Expand Down
3 changes: 3 additions & 0 deletions src/json-crdt-extensions/peritext/slice/ExtraSlices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Slices} from './Slices';

export class ExtraSlices extends Slices {}

0 comments on commit c529aaf

Please sign in to comment.