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

42.85% Statements 3/7
100% Branches 0/0
0% Functions 0/1
42.85% Lines 3/7

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 2360x 60x                 60x                        
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);
  }
}