Skip to content

Conversation

zamora-carlos
Copy link
Contributor

Description

When the user clicks a file or directory in the directory structure tree, the full relative path should be copied into the pattern input field. Currently, clicking on nested files in the tree inserts an incorrect or incomplete path. This pull request addresses that issue.

Closes #288

Changes

The getFileName and toggleFile functions in src/server/templates/components/result.jinja were modified to correctly compute the full path of a clicked file by traversing DOM elements and extracting its parent directories.

Previously, the regex used to detect the start of the filename was /[a-zA-Z0-9]/. It has now been updated to /[a-zA-Z0-9_.-]/ to correctly handle filenames starting with a dot or underscore (e.g., .gitignore, __init__.py). An alternative approach could be to match the first character that is not a box-drawing or whitespace character ("|", "└", "├", "─", space).

To determine parent directories, we use the fact that each level of indentation is 4 characters wide. By traversing up the DOM tree from the clicked element and checking for nodes with decreasing indentation levels, we can reconstruct the full relative path.

An early return has been added for clicks on the account and repository name in the directory tree, as this item doesn’t affect the result. Previously, only the header was excluded from interaction.

Testing

I performed manual testing on a few repositories to confirm that files are correctly excluded after submitting the form. I've attached a screenshot showing the generated file paths.

Screenshot 2025-06-22 at 2 50 42 a m

Copy link
Member

@cyclotruc cyclotruc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it and it works wonderfully!

Very few changes as well great job, merging
thank you very much @zamora-carlos

@cyclotruc cyclotruc merged commit 3c53843 into coderamp-labs:main Jun 22, 2025
18 checks passed
@filipchristiansen
Copy link
Contributor

Thanks a lot @zamora-carlos for the quick fix with minimal changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(web ui): directory-picker inserts incomplete or mangled paths
3 participants