(query, options)
| 289 | |
| 290 | // :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'. |
| 291 | static execute(query, options) { |
| 292 | let result = null; |
| 293 | options = Object.assign({ |
| 294 | backwards: false, |
| 295 | caseSensitive: !this.query.ignoreCase, |
| 296 | colorSelection: true, |
| 297 | }, options); |
| 298 | if (query == null) { |
| 299 | query = FindMode.getQuery(options.backwards); |
| 300 | } |
| 301 | |
| 302 | if (options.colorSelection) { |
| 303 | document.body.classList.add("vimium-find-mode"); |
| 304 | // ignore the selectionchange event generated by find() |
| 305 | document.removeEventListener("selectionchange", this.restoreDefaultSelectionHighlight, true); |
| 306 | } |
| 307 | |
| 308 | if (this.query.regexMatches?.length) { |
| 309 | const [row, col] = this.query.activeRegexIndices; |
| 310 | const node = this.query.regexMatchedNodes[row]; |
| 311 | const text = node.textContent; |
| 312 | const matchIndices = getRegexMatchIndices(text, this.query.regexPattern); |
| 313 | if (matchIndices.length > 0) { |
| 314 | const startIndex = matchIndices[col]; |
| 315 | result = highlight(node, startIndex, query.length); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // window.find focuses the |window| that it is called on. This gives us an opportunity to |
| 320 | // (re-)focus another element/window, if that isn't the behaviour we want. |
| 321 | if (options.postFindFocus != null) { |
| 322 | options.postFindFocus.focus(); |
| 323 | } |
| 324 | |
| 325 | if (options.colorSelection) { |
| 326 | setTimeout( |
| 327 | () => |
| 328 | document.addEventListener("selectionchange", this.restoreDefaultSelectionHighlight, true), |
| 329 | 0, |
| 330 | ); |
| 331 | } |
| 332 | |
| 333 | // We are either in normal mode ("n"), or find mode ("/"). We are not in insert mode. |
| 334 | // Nevertheless, if a previous find landed in an editable element, then that element may still |
| 335 | // be activated. In this case, we don't want to leave it behind (see #1412). |
| 336 | if (document.activeElement && DomUtils.isEditable(document.activeElement)) { |
| 337 | if (!DomUtils.isSelected(document.activeElement)) { |
| 338 | document.activeElement.blur(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | return result; |
| 343 | } |
| 344 | |
| 345 | // The user has found what they're looking for and is finished searching. We enter insert mode, if |
| 346 | // possible. |
no test coverage detected