Skip to content

Commit

Permalink
fix: report_template glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
zeefxd committed Dec 4, 2024
1 parent d3722ed commit 193c470
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/utils/report_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -382,30 +382,38 @@ <h4>Unique Destinations</h4>
let matches = [];

function search() {
// Reset previous search
clearHighlights();
matches = [];
currentMatchIndex = -1;

const searchText = document.getElementById('searchInput').value.toLowerCase();
if (!searchText) return;

const content = document.querySelectorAll('.data-table td');

content.forEach(cell => {
const text = cell.innerText.toLowerCase();
if (text.includes(searchText)) {
const text = cell.textContent;
if (text.toLowerCase().includes(searchText)) {
const regex = new RegExp(searchText, 'gi');
cell.innerHTML = cell.innerText.replace(regex, match =>
`<span class="highlight">${match}</span>`
);

// Collect all highlights
const highlights = cell.getElementsByClassName('highlight');
matches.push(...highlights);
const fragments = text.split(regex);
const highlights = text.match(regex);

// Clear cell content
cell.textContent = '';

fragments.forEach((fragment, index) => {
cell.appendChild(document.createTextNode(fragment));
if (index < highlights.length) {
const highlightSpan = document.createElement('span');
highlightSpan.className = 'highlight';
highlightSpan.textContent = highlights[index];
cell.appendChild(highlightSpan);
matches.push(highlightSpan);
}
});
}
});

updateMatchCount();
if (matches.length > 0) {
goToMatch(0);
Expand Down

0 comments on commit 193c470

Please sign in to comment.