---
title: "tinymce.dom.TextSeeker"
description: "The TextSeeker class enables you to seek for a specific point in text across the DOM."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.textseeker/"
md_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.textseeker/index.md"
version: "latest"
last_updated: "2022-06-27T01:45:26Z"
tokens: 706
---
# tinymce.dom.TextSeeker

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

## Examples

```javascript
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()](#TextSeeker) | Constructs a new TextSeeker instance. | `TextSeeker` |

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [backwards()](#backwards) | Search backwards through text nodes until a match, boundary, or root node has been found. | `TextSeeker` |
| [forwards()](#forwards) | Search forwards through text nodes until a match, boundary, or root node has been found. | `TextSeeker` |

## Constructors

### TextSeeker

```javascript
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()

```javascript
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()

```javascript
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.
