Skip to content

Commit

Permalink
feat(json-crdt-extensions): 馃幐 improve MarkerOverlayPoint presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Apr 28, 2024
1 parent 5847c75 commit b6b6521
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/json-crdt-extensions/peritext/overlay/MarkerOverlayPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {Anchor} from '../rga/constants';
import type {AbstractRga} from '../../../json-crdt/nodes/rga';
import type {ITimestampStruct} from '../../../json-crdt-patch/clock';
import type {MarkerSlice} from '../slice/MarkerSlice';
import {printTree} from 'sonic-forest/lib/print/printTree';

export class MarkerOverlayPoint extends OverlayPoint {
/**
Expand All @@ -23,21 +24,23 @@ export class MarkerOverlayPoint extends OverlayPoint {
return this.marker ? this.marker.hash : 0;
}

public tag(): SliceType | 0 {
if (!this.marker) return 0;
return this.marker.type;
public type(): SliceType {
return this.marker && this.marker.type;
}

public data(): unknown {
if (!this.marker) return undefined;
return this.marker.data();
return this.marker && this.marker.data();
}

// ---------------------------------------------------------------- Printable

public toStringName(tab: string, lite?: boolean): string {
const hash = lite ? '' : `#${this.textHash.toString(36).slice(-4)}`;
const tag = lite ? '' : `, ${JSON.stringify((this.tag() as any)[1])}`;
const tag = lite ? '' : `, type = ${JSON.stringify((this.type() as any))}`;
return `${super.toStringName(tab, lite)}${lite ? '' : ' '}${hash}${tag}`;
}

public toString(tab: string = '', lite?: boolean): string {
return super.toString(tab, lite) + (lite ? '' : printTree(tab, [tab => this.marker.toString(tab)]));
}
}

0 comments on commit b6b6521

Please sign in to comment.