* Finds the next/previous search result * @param {number} skip Number of search results to skip * @param {boolean} backward Whether to search backward
(skip, backward)
| 527 | * @param {boolean} backward Whether to search backward |
| 528 | */ |
| 529 | function find(skip, backward) { |
| 530 | const { $searchInput } = quickTools; |
| 531 | const { activeFile } = editorManager; |
| 532 | |
| 533 | // Check if current tab is a terminal |
| 534 | if ( |
| 535 | activeFile && |
| 536 | activeFile.type === "terminal" && |
| 537 | activeFile.terminalComponent |
| 538 | ) { |
| 539 | activeFile.terminalComponent.search($searchInput.value, skip, backward); |
| 540 | } else { |
| 541 | const editor = editorManager.editor; |
| 542 | const searchValue = getRefValue($searchInput); |
| 543 | const query = applySearchQuery(editor, searchValue); |
| 544 | if (!query || !query.search || !query.valid) { |
| 545 | updateSearchState(); |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | const normalizedSkip = Number(skip) || 0; |
| 550 | if (normalizedSkip === 0 && selectionMatchesQuery(editor, query)) { |
| 551 | updateSearchState(); |
| 552 | return; |
| 553 | } |
| 554 | const steps = Math.max(1, normalizedSkip); |
| 555 | const runCommand = backward ? cmFindPrevious : cmFindNext; |
| 556 | for (let i = 0; i < steps; ++i) { |
| 557 | if (!runCommand(editor)) break; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | updateSearchState(); |
| 562 | } |
| 563 | |
| 564 | function updateSearchState() { |
| 565 | const MAX_COUNT = 999; |
no test coverage detected