How to use the prosemirror-state.Selection function in prosemirror-state

To help you get started, we’ve selected a few prosemirror-state examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github guardian / prosemirror-noting / test / helpers / prosemirror.js View on Github external
delete(n = 1) {
    for (let i = 0; i < n; i += 1) {
      const { $cursor } = this.selection;

      const { from, to } = $cursor
        ? new Selection(this.selection.$from, this.rightPos.$from)
        : this.selection;

      this.apply(this.tr.replace(from, to, Slice.empty));
    }
    return this;
  }
github guardian / prosemirror-noting / test / helpers / prosemirror.js View on Github external
backspace(n = 1) {
    for (let i = 0; i < n; i += 1) {
      const { $cursor } = this.selection;

      const { from, to } = $cursor
        ? new Selection(this.leftPos.$from, this.selection.$from)
        : this.selection;

      this.apply(this.tr.replace(from, to, Slice.empty));
    }
    return this;
  }
github guardian / prosemirror-noting / test / helpers / prosemirror.js View on Github external
selectRight(n = 1) {
    const { $from } = this.state.selection;
    let { $to } = this.state.selection;
    for (let i = 0; i < n; i += 1) {
      const $pos = this.state.doc.resolve($to.pos + 1);
      $to = Selection.near($pos).$to;
    }
    
    return this.setSelection(new Selection($from, $to));
  }
github guardian / prosemirror-noting / src / js / utils / range.ts View on Github external
export const expandRange = (range: Range, doc: Node): Range => {
  const $fromPos = doc.resolve(range.from);
  const $toPos = doc.resolve(range.to);
  const parentNode = findParentNode(node => node.isBlock)(
    new Selection($fromPos, $toPos)
  );
  if (!parentNode) {
    throw new Error(
      `Parent node not found for position ${$fromPos.start}, ${$fromPos.end}`
    );
  }
  return {
    from: parentNode.start,
    to: parentNode.start + parentNode.node.textContent.length
  };
};