MCPcopy Create free account
hub / github.com/error311/FileRise / maybeHighlightSearchedFile

Function maybeHighlightSearchedFile

public/js/fileListView.js:8593–8657  ·  view source on GitHub ↗
(folder)

Source from the content-addressed store, hash-verified

8591}
8592
8593function maybeHighlightSearchedFile(folder) {
8594 if (!pendingSearchSelection) return;
8595 const target = pendingSearchSelection;
8596 if (!target || target.folder !== folder) return;
8597 const name = target.name;
8598 if (!name) return;
8599
8600 const findRow = () => {
8601 const nodes = document.querySelectorAll('#fileList tr[data-file-name], .gallery-card[data-file-name]');
8602 for (const row of nodes) {
8603 const raw = row.getAttribute('data-file-name') || '';
8604 const decoded = decodeHtmlEntities(raw);
8605 if (raw === name || decoded === name) return row;
8606 }
8607 return null;
8608 };
8609
8610 try {
8611 const row = findRow();
8612 if (!row) {
8613 if (typeof target.retries !== 'number') target.retries = 10;
8614 if (target.retries > 0) {
8615 target.retries -= 1;
8616 // Try again shortly in case the DOM finishes rendering
8617 setTimeout(() => maybeHighlightSearchedFile(folder), 120);
8618 }
8619 pendingSearchSelection = target;
8620 return;
8621 }
8622
8623 const alreadySelected = row.classList.contains('row-selected') || row.classList.contains('selected');
8624
8625 // Select checkbox if present
8626 const cb = row.querySelector('.file-checkbox');
8627 if (cb && !alreadySelected) {
8628 // clear other selections
8629 document.querySelectorAll('#fileList .file-checkbox').forEach(box => {
8630 if (box !== cb) {
8631 box.checked = false;
8632 updateRowHighlight(box);
8633 }
8634 });
8635 cb.checked = true;
8636 updateRowHighlight(cb);
8637 updateFileActionButtons();
8638 } else if (!cb && !alreadySelected) {
8639 row.classList.add('row-selected', 'selected');
8640 }
8641
8642 if (!alreadySelected) {
8643 row.scrollIntoView({ behavior: 'smooth', block: 'center' });
8644 }
8645
8646 if (!target.clearTimer) {
8647 const ref = target;
8648 target.clearTimer = setTimeout(() => {
8649 if (pendingSearchSelection === ref) {
8650 pendingSearchSelection = null;

Callers 4

navigateToSearchResultFunction · 0.85
loadFileListFunction · 0.85
renderFileTableFunction · 0.85
renderGalleryViewFunction · 0.85

Calls 3

findRowFunction · 0.85
updateRowHighlightFunction · 0.85
updateFileActionButtonsFunction · 0.85

Tested by

no test coverage detected