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;
}
});
Constructors
name | summary | defined by |
---|---|---|
TextSeeker() | Constructs a new TextSeeker instance. | tinymce.dom.TextSeeker |
Methods
name | summary | defined by |
---|---|---|
backwards() | Search backwards through text nodes until a match, boundary, or root node has been found. Added in TinyMCE 5.2 | tinymce.dom.TextSeeker |
forwards() | Search forwards through text nodes until a match, boundary, or root node has been found. Added in TinyMCE 5.2 | tinymce.dom.TextSeeker |
Constructors
TextSeeker
public constructor function TextSeeker(dom:tinymce.dom.DOMUtils, isBoundary:Function)
Constructs a new TextSeeker instance.
Parameters
- dom (tinymce.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.
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.
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.
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.
Return value
- Object - An object containing the matched text node and offset. If no match is found, null will be returned.
Can't find what you're looking for? Let us know.
Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.