Skip to content

Commit 3d64849

Browse files
Fix to log file flicker with filter
1 parent 84a90cf commit 3d64849

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

‎apps/predbat/web_helper.py‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,10 @@ def get_logfile_js(filter_type):
23332333
const shouldAutoScroll = autoScroll ? autoScroll.checked : false;
23342334
let newEntriesAdded = 0;
23352335
2336+
// Get current search filter to apply immediately
2337+
const searchTerm = document.getElementById('logSearchInput').value.toLowerCase();
2338+
const hasSearchFilter = searchTerm.trim() !== '';
2339+
23362340
// Insert new entries at the top (newest first)
23372341
lines.forEach(logLine => {{
23382342
if (logLine.line_number > lastLineNumber) {{
@@ -2352,6 +2356,18 @@ def get_logfile_js(filter_type):
23522356
23532357
row.innerHTML = `<td>${{logLine.line_number}}</td><td nowrap><font color="${{color}}">${{timestamp}}</font> ${{message}}</td>`;
23542358
2359+
// Apply search filter immediately if one is active
2360+
if (hasSearchFilter) {{
2361+
const rowText = row.textContent.toLowerCase();
2362+
if (rowText.includes(searchTerm)) {{
2363+
// Entry matches filter - highlight and show it
2364+
highlightTextInElement(row, searchTerm);
2365+
}} else {{
2366+
// Entry doesn't match filter - hide it immediately
2367+
row.classList.add('log-entry-hidden');
2368+
}}
2369+
}}
2370+
23552371
// Insert at the top of the table body
23562372
tbody.insertBefore(row, tbody.firstChild);
23572373
newEntriesAdded++;
@@ -2360,13 +2376,13 @@ def get_logfile_js(filter_type):
23602376
}}
23612377
}});
23622378
2363-
// Apply current search filter to new entries
2364-
const searchTerm = document.getElementById('logSearchInput').value.toLowerCase();
2365-
if (searchTerm.trim() !== '') {{
2366-
// Re-apply filter to include new entries
2367-
setTimeout(() => {{
2368-
filterLogEntries();
2369-
}}, 50);
2379+
// Update search status if we have a filter active
2380+
if (hasSearchFilter && newEntriesAdded > 0) {{
2381+
const rows = document.querySelectorAll('#logTableBody tr[data-line]');
2382+
const statusDiv = document.getElementById('searchStatus');
2383+
const visibleCount = Array.from(rows).filter(row => !row.classList.contains('log-entry-hidden')).length;
2384+
const totalCount = rows.length;
2385+
statusDiv.textContent = `Showing ${{visibleCount}} of ${{totalCount}} entries`;
23702386
}}
23712387
23722388
// Auto-scroll to top for new entries (since newest are at top)

0 commit comments

Comments
 (0)