tinymce.dom.TextSeeker
The TextSeeker class enables you to seek for a specific point in text across the DOM.
Examples
var startOfWord = TextSeeker(editor.dom).backwards(startNode, startOffset, function(textNode, offset, text) {
var lastSpaceCharIndex = text.lastIndexOf(' ');
if (lastSpaceCharIndex !== -1) {
return lastSpaceCharIndex + 1;
} else {
// No space found so continue searching
return -1;
}
});
Summary
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 orbr
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.
Added in TinyMCE 5.2
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.
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.
Added in TinyMCE 5.2
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.