All files / json-crdt-extensions/peritext/slice MarkerSlice.ts

66.66% Statements 8/12
100% Branches 0/0
66.66% Functions 2/3
66.66% Lines 8/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3364x 64x                 64x                         18x 18x 18x   18x   18x      
import {Anchor} from '../rga/constants';
import {PersistedSlice} from './PersistedSlice';
import type {Range} from '../rga/Range';
 
/**
 * Represents a block split in the text, i.e. it is a *marker* that shows
 * where a block was split. Markers also insert one "\n" new line character.
 * Both marker ends are attached to the "before" anchor fo the "\n" new line
 * character, i.e. it is *collapsed* to the "before" anchor.
 */
export class MarkerSlice<T = string> extends PersistedSlice<T> {
  /**
   * Returns the {@link Range} which exactly contains the block boundary of this
   * marker.
   */
  public boundary(): Range<T> {
    const start = this.start;
    const end = start.clone();
    end.anchor = Anchor.After;
    return this.txt.range(start, end);
  }
 
  public del(): void {
    super.del();
    const txt = this.txt;
    const range = txt.range(
      this.start,
      this.start.copy((p) => (p.anchor = Anchor.After)),
    );
    txt.delStr(range);
  }
}