* Find preview or next value, and highlight it. * @param {string} action : previous or next.
(action: 'previous' | 'next')
| 111 | * @param {string} action : previous or next. |
| 112 | */ |
| 113 | find(action: 'previous' | 'next'): this { |
| 114 | const { matches } = this; |
| 115 | let { index } = this; |
| 116 | const len = matches.length; |
| 117 | |
| 118 | if (!len) |
| 119 | return this; |
| 120 | |
| 121 | index = action === 'next' ? index + 1 : index - 1; |
| 122 | |
| 123 | if (index < 0) |
| 124 | index = len - 1; |
| 125 | |
| 126 | if (index >= len) |
| 127 | index = 0; |
| 128 | |
| 129 | this.index = index; |
| 130 | |
| 131 | this._updateMatches(true); |
| 132 | this._updateMatches(); |
| 133 | |
| 134 | return this; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Search value in current document. |