fix(ui): update directory-picker logic to compute full file paths #295
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andtoggleFile
functions insrc/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.