| 733 | }, |
| 734 | |
| 735 | runSearch() { |
| 736 | const query = String(this.searchQuery || ""); |
| 737 | if (!query) { |
| 738 | this.searchMatches = []; |
| 739 | this.searchIndex = -1; |
| 740 | this.schedulePreviewEnhance(); |
| 741 | return; |
| 742 | } |
| 743 | const lower = query.toLowerCase(); |
| 744 | const matches = []; |
| 745 | for (const page of this.pages()) { |
| 746 | const text = this.renderedTextForPage(page); |
| 747 | let index = 0; |
| 748 | let occurrence = 0; |
| 749 | while ((index = text.toLowerCase().indexOf(lower, index)) >= 0) { |
| 750 | matches.push({ pageIndex: page.index, occurrence, offset: index }); |
| 751 | occurrence += 1; |
| 752 | index += Math.max(1, lower.length); |
| 753 | } |
| 754 | } |
| 755 | this.searchMatches = matches; |
| 756 | this.searchIndex = matches.length ? 0 : -1; |
| 757 | this.goToCurrentSearchMatch(); |
| 758 | }, |
| 759 | |
| 760 | nextSearchMatch() { |
| 761 | if (!this.searchMatches.length) return; |