Skip to content

feat: Focus on current directory on navigation to parent directory in a filepanel#1340

Merged
lazysegtree merged 3 commits into
yorukot:mainfrom
xelavopelk:fix_navigate_back
Feb 2, 2026
Merged

feat: Focus on current directory on navigation to parent directory in a filepanel#1340
lazysegtree merged 3 commits into
yorukot:mainfrom
xelavopelk:fix_navigate_back

Conversation

@xelavopelk

@xelavopelk xelavopelk commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

problem:
0) The process starts in the directory "~/repo/golang/superfile-klepov".
image

  1. I try to go up to the parent directory. However, the focused directory is not "superfile-klepov", which is not the expected behavior. The focus is correct when it is in the cache m.DirectoryRecords only.
image

Up to parent after fix:
image

Summary by CodeRabbit

  • Tests

    • Added/renamed coverage for directory navigation, including a new subtest ensuring focus stays on the current directory after navigating to its parent.
  • Bug Fixes

    • When switching to a parent directory, preserve the previously selected file name and restore cached cursor/render positions when available; otherwise reset positions. Documented cache behavior during directory transitions.

@coderabbitai

coderabbitai Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Renamed a test case and added a new subtest to assert focus behavior when navigating to a parent directory; updated file-panel directory-switch logic to set TargetFile when moving to a parent and to restore or reset cached cursor and renderIndex from DirectoryRecord.

Changes

Cohort / File(s) Summary
Navigation tests
src/internal/model_navigation_test.go
Renamed test case ("Enter via cd command" → "Enter via cd command first dir", adjusted startCursor) and added a new subtest "Focus on current directory on navigation to parent directory" that uses an event-loop to send ParentDirectory and asserts focused item location and cursor.
File panel directory update logic
src/internal/ui/filepanel/update.go
Added path/filepath import; when switching to a parent directory set m.TargetFile = filepath.Base(m.Location) before updating m.Location; replaced TODO with NOTE about cache invalidation; after switching restore cursor and renderIndex from DirectoryRecord if present, otherwise reset both to 0.

Sequence Diagram(s)

(Skipped — conditions for generating sequence diagrams not met.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

bug fixes

Suggested reviewers

  • yorukot

Poem

🐰 I hopped from dir down to parent lane,
Kept track of names and where cursors reign,
A basename saved before I roam,
Cursors restored to find their home,
Cheers from a rabbit — code paths tamed! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and clearly describes the main change: implementing focus behavior on the current directory when navigating to the parent directory in a file panel, which matches the core functionality added in both test and implementation files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xelavopelk

Copy link
Copy Markdown
Contributor Author

@lazysegtree
does we need in cache here? It seems that cache misses are inevitable here. The same applies to positioning errors due to cache.
image

Comment thread src/internal/ui/filepanel/update.go Outdated
return fmt.Errorf("%s is not a directory", path)
}

m.TargetFile = filepath.Base(m.Location)

@lazysegtree lazysegtree Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should not be done always @xelavopelk. It should be done only when you are switch to parent directory.

In this case, when users press confirm on directory ./b/c They will go to ./b/c/b instead of correct ./b/c/a

➜  ~/temp/testf/a [8:46:23] find .
.
./b
./b/c
./b/c/a2
./b/c/a
./b/c/b
➜  ~/temp/testf/a [8:46:26]

@lazysegtree

Copy link
Copy Markdown
Collaborator

@lazysegtree
does we need in cache here?

I don't understand what that means, but don't mind that comment. I have fixed it.

lazysegtree
lazysegtree previously approved these changes Feb 2, 2026
@lazysegtree lazysegtree changed the title fix: fixed uncached navigation back in a filepanel feat: Focus on current directory on navigation to parent directory in a filepanel Feb 2, 2026
@lazysegtree

Copy link
Copy Markdown
Collaborator

FYI, this is not a bug fix. The way it worked before was the intended behaviour.

Comment thread src/internal/model_navigation_test.go Outdated
Comment on lines +103 to +115
{
name: "Enter via cd command second dir",
startDir: curTestDir,
resultDir: dir2,
startCursor: 1,
keyInput: []string{
common.Hotkeys.OpenSPFPrompt[0],
// TODO : Have it quoted, once cd command supports quoted paths
"cd " + dir2,
common.Hotkeys.ConfirmTyping[0],
},
searchBarClear: true,
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This unit test is pointless and will pass even without the fix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When you add unit tests, please understand what they are doing and if they even add any value.

@lazysegtree

Copy link
Copy Markdown
Collaborator

Let me know if you are good with the PR, I will merge it then.

@xelavopelk

Copy link
Copy Markdown
Contributor Author

Let me know if you are good with the PR, I will merge it then.

ok. thanks for help.

@lazysegtree lazysegtree merged commit d9a7274 into yorukot:main Feb 2, 2026
7 of 10 checks passed
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.

2 participants