tinymce.dom.TextSeeker

The TextSeeker class enables you to seek for a specific point in text across the DOM.

Examples

const seeker = tinymce.dom.TextSeeker(editor.dom);
const startOfWord = seeker.backwards(startNode, startOffset, (textNode, offset, text) => {
  const lastSpaceCharIndex = text.lastIndexOf(' ');
  if (lastSpaceCharIndex !== -1) {
    return lastSpaceCharIndex + 1;
  } else {
    // No space found so continue searching
    return -1;
  }
});

Summary

Constructors

Name Summary Defined by

TextSeeker()

Constructs a new TextSeeker instance.

TextSeeker

Methods

Name Summary Defined by

backwards()

Search backwards through text nodes until a match, boundary, or root node has been found.

TextSeeker

forwards()

Search forwards through text nodes until a match, boundary, or root node has been found.

TextSeeker

Constructors

TextSeeker

public constructor function TextSeeker(dom: tinymce.dom.DOMUtils, isBoundary: Function)

Constructs a new TextSeeker instance.

Parameters

  • dom (DOMUtils) - DOMUtils object reference.

  • isBoundary (Function) - Optional function to determine if the seeker should continue to walk past the node provided. The default is to search until a block or br element is found.

Methods

backwards()

backwards(node: Node, offset: Number, process: Function, root: Node): Object

Search backwards through text nodes until a match, boundary, or root node has been found.

Parameters

  • node (Node) - The node to start searching from.

  • offset (Number) - The offset of the node to start searching from.

  • process (Function) - A function that’s passed the current text node, the current offset and the text content of the node. It should return the offset of the match or -1 to continue searching.

  • root (Node) - An optional root node to constrain the search to.

Return value

  • Object - An object containing the matched text node and offset. If no match is found, null will be returned.


forwards()

forwards(node: Node, offset: Number, process: Function, root: Node): Object

Search forwards through text nodes until a match, boundary, or root node has been found.

Parameters

  • node (Node) - The node to start searching from.

  • offset (Number) - The offset of the node to start searching from.

  • process (Function) - A function that’s passed the current text node, the current offset and the text content of the node. It should return the offset of the match or -1 to continue searching.

  • root (Node) - An optional root node to constrain the search to.

Return value

  • Object - An object containing the matched text node and offset. If no match is found, null will be returned.