Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/server/templates/components/result.jinja
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
<script>
function getFileName(line) {
// Skips "|", "└", "├" found in file tree
const index = line.search(/[a-zA-Z0-9]/);
return line.substring(index).trim();
function getFileName(element) {
const indentSize = 4;
let path = "";
let prevIndentLevel = null;

while (element) {
const line = element.textContent;
const index = line.search(/[a-zA-Z0-9_.-]/);
const indentLevel = index / indentSize;

// Stop when we reach or go above the top-level directory
if (indentLevel <= 1) {
break;
}

// Only include directories that are one level above the previous
if (prevIndentLevel === null || indentLevel === prevIndentLevel - 1) {
const fileName = line.substring(index).trim();
path = fileName + path;
prevIndentLevel = indentLevel;
}

element = element.previousElementSibling;
}

return path;
}

function toggleFile(element) {
const patternInput = document.getElementById("pattern");
const patternFiles = patternInput.value ? patternInput.value.split(",").map(item => item.trim()) : [];

if (element.textContent.includes("Directory structure:")) {
const directoryContainer = document.getElementById("directory-structure-container");
const treeLineElements = Array.from(directoryContainer.children).filter(child => child.tagName === "PRE");

// Skip the first two tree lines (header and repository name)
if (treeLineElements[0] === element || treeLineElements[1] === element) {
return;
}

element.classList.toggle('line-through');
element.classList.toggle('text-gray-500');

const fileName = getFileName(element.textContent);
const fileName = getFileName(element);
const fileIndex = patternFiles.indexOf(fileName);

if (fileIndex !== -1) {
Expand Down
Loading