Skip to content

feat(file_panel): add follow navigation#233

Closed
jensenojs wants to merge 2 commits into
dlyongemallo:mainfrom
jensenojs:feat/file-panel-follow-navigation
Closed

feat(file_panel): add follow navigation#233
jensenojs wants to merge 2 commits into
dlyongemallo:mainfrom
jensenojs:feat/file-panel-follow-navigation

Conversation

@jensenojs

Copy link
Copy Markdown

Summary

Allow users to keep the file panel focused while browsing diffs with j / k.

This adds an opt-in file_panel.follow_navigation setting. When enabled, the existing file-panel next_entry / prev_entry actions also preview the file under the cursor without moving focus out of the panel.

The default behavior and default keymaps stay unchanged. Users who want this behavior only on selected mappings can use the new actions.next_entry_follow and actions.prev_entry_follow actions directly.

Why the focus fix is included

file_panel.follow_navigation relies on set_file(..., focus=false, ...) so that previewing a file does not move focus out of the file panel.

Some file changes recreate the diff layout, for example when view.one_sided_layout = "raw" switches between a two-window diff layout and a one-window raw layout. The layout recreation could move focus back to the diff window even though the caller passed focus=false.

This PR preserves the original file-panel focus across that layout swap.

@dlyongemallo

Copy link
Copy Markdown
Owner

I don't understand what this change does. AFAICT, the behaviour you describe is already the existing behaviour with <tab>/<s-tab>.

If you just want this behaviour mapped to j/k, why can't you just set this in your config?

  keymaps = {                                                                                                                                                                         
    file_panel = {                                                                                                                                                                    
      { "n", "j", actions.select_next_entry, { desc = "Open diff for next file" } },                                                                                                  
      { "n", "k", actions.select_prev_entry, { desc = "Open diff for previous file" } },                                                                                              
    },                                                                                                                                                                                
  }                                                                                                                                                                                   

Also, can you describe the bug behind the layout swap restore focus fix? For example, what is a repro case?

@dlyongemallo

Copy link
Copy Markdown
Owner

Okay, I've reproduced the bug and verified 9660f7a fixes it.

@dlyongemallo

Copy link
Copy Markdown
Owner

I've merged the fix. I'm still not sure about the feature request.

@jensenojs

Copy link
Copy Markdown
Author

Thanks, and sorry for the noise.

You were right about the feature request. I had just migrated from diffview.nvim, where I don't think this behavior was available in the same way. I already had a small local patch for it, and when I moved over to this fork for other reasons, I accidentally carried that patch along with the focus fix without checking the existing mappings carefully enough.

@jensenojs jensenojs closed this Jun 12, 2026
@jensenojs jensenojs deleted the feat/file-panel-follow-navigation branch June 12, 2026 13:35
@dlyongemallo

Copy link
Copy Markdown
Owner

@jensenojs Thanks for the focus bug fix!

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