ISSUE-627: Fix file tree navigation while filter active#707
Open
herbenderbler wants to merge 1 commit into
Open
ISSUE-627: Fix file tree navigation while filter active#707herbenderbler wants to merge 1 commit into
herbenderbler wants to merge 1 commit into
Conversation
Navigation evaluators required each node to match the filter regex, while rendering kept ancestor directories of matches visible. This desynced the cursor index from the rendered tree, so collapse and expand became a no op under an active filter. Derive cursor visibility from the Hidden flag that Update already computes instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #627
Synopsis
When a path filter was active, the file tree became unnavigable. Pressing
Space(collapse/expand) or the arrow keys did nothing and the highlighted rowcould be misaligned from the node that actions operated on.
The reported reproduction:
dive alpineTabto focus the file treeCtrl+Spaceto collapse all directoriesCtrl+F, typelsto filterTabTabto leave the filter input while keeping the filter activeSpaceto try to expandbin— nothing happensRoot cause
dive keeps two trees:
ViewTreeis what you see.Update()keeps a directory visible if it (orany descendant) matches the filter, so ancestor directories of a match (e.g.
/etcwhen filteringnetwork) stay on screen even though they do not matchthe regex themselves.
ModelTreeis what the cursor navigates. All positioning logic(
getAbsPositionNode,CursorLeft,CursorRight,ToggleCollapse) walkedthe
ModelTreewith an evaluator that required each node to match the regexitself.
Because
VisitDepthParentFirstprunes the entire subtree of any node that failsthe evaluator, a non matching ancestor like
/etcwas never counted and itsmatching children were never reached. The cursor index space therefore diverged
from the rendered tree. In the collapse all case nothing satisfied the
evaluator at all, so
getAbsPositionNodereturnedniland collapse/expandbecame a no op.
Fix
Navigation now derives visibility from the same
Data.ViewInfo.Hiddenflag thatUpdate()already computes (filter aware, ancestor preserving) and thatVisibleSize()and rendering already use. The per node regex test was removedfrom the navigation evaluators:
With the filter interpreted in exactly one place (
Update), the redundantfilterRegexparameter was dropped fromgetAbsPositionNode,CurrentNode,CursorLeft,CursorRight, andToggleCollapse. The cursor index space nowmatches the rendered tree exactly, so directories such as
/etcare selectableand expandable while a filter is active.
How to test
Manual verification through a Docker daemon
Requires a running Docker daemon. From the repo root:
Inside the TUI, follow the issue's exact steps:
Tabto focus the file tree paneCtrl+Spaceto collapse all directoriesCtrl+F, typels, to apply the filterTabTabto leave the filter input while keeping the filter activebinand pressSpace(orRight)Expected: the directory expands/collapses and the cursor stays aligned with the
highlighted row. Before the fix this was a no op.
A deeper image makes the desync more obvious:
Repeat the steps above. Also try without collapse all:
Ctrl+F, typepasswd,TabTab, move onto the visibleetcdirectory, then pressSpace/Rightand confirm the directory under the cursor is the one that toggles.
Clear the filter and confirm unfiltered navigation is unchanged.
Regression tests
No Docker required.
The new tests are:
TestFileTreeNavigateWithActiveFilter— filteringnetworkkeeps/etc(a non matching ancestor of the match) selectable and collapsible.
TestFileTreeNavigateCollapseAllThenFilter— the issue's exact sequence(collapse all, then filter, then expand) leaves
/etcselectable andexpandable.
Both fail against the previous behavior with
CurrentNode()returningnil(the navigation unresponsive symptom) and pass with the fix. Existing snapshot
tests continue to pass, confirming the rendered output is unchanged.