Skip to content

fix(explorer): allow file navigation before a hidden explorer is first shown - #568

Open
MarcusGasberg wants to merge 1 commit into
esmuellert:mainfrom
MarcusGasberg:fix/explorer-hidden-navigation
Open

MarcusGasberg wants to merge 1 commit into
esmuellert:mainfrom
MarcusGasberg:fix/explorer-hidden-navigation

Conversation

@MarcusGasberg

Copy link
Copy Markdown

Summary

With explorer = { hidden = true }, next_file/prev_file (]f/[f) throw until the explorer has been toggled open at least once:

E5108: Lua: .../codediff/ui/explorer/actions.lua:61: Invalid 'win': Expected Lua number
stack traceback:
        [C]: in function 'nvim_win_is_valid'
        .../codediff/ui/explorer/actions.lua:61: in function 'navigate_next'
        .../codediff/ui/view/navigation.lua:210: in function <.../codediff/ui/view/navigation.lua:190>

render.create hides the split right after mounting it, and Split:hide() clears split.winid, so explorer.winid starts out nil. navigate_next/navigate_prev pass it straight to nvim_win_is_valid, which rejects nil. After the first toggle winid holds a window id (valid or stale), which is why the error only appears before the panel has ever been shown.

Changes

  • lua/codediff/ui/explorer/actions.lua: guard the tree-cursor sync in navigate_next and navigate_prev with explorer.winid and ..., the same check toggle_staged_view and render.create already use.
  • tests/e2e/explorer/actions_spec.lua: add [E21], which sets explorer.hidden = true, then drives next_file and prev_file from the diff pane and checks the comparison changes each time.

Benefits

explorer.hidden = true is usable with keyboard file navigation from the moment a session opens, instead of requiring a show/hide of the panel first.

Testing

  • ./tests/run_tests.sh tests/e2e/explorer/actions_spec.lua: 84 passed, 0 failed (E21 passes for native/polling × side-by-side/inline). Without the fix, E21 never completes: the mapping error leaves the embedded Neovim at a hit-enter prompt and the spec hits the 300s per-spec timeout.
  • ./tests/run_tests.sh (full suite, Linux, Neovim 0.12.5): 1587 passed, 18 failed. All 18 failures are in tests/integration/ui/conflict/gutter_grid_spec.lua (screen-grid glyph assertions, e.g. expected │ ╱╱╱╱, actual ╰─╱╱╱╱), and that spec fails identically on unmodified main in this environment, so it's unrelated to this change.
  • stylua --check clean on both files.

🤖 Generated with Claude Code

…t shown

With explorer.hidden = true, the explorer split is hidden right after it
is mounted, which clears its winid. navigate_next/navigate_prev passed
that nil straight to nvim_win_is_valid, so next_file/prev_file threw
"Invalid 'win': Expected Lua number" until the panel had been shown once.

Guard the tree-cursor sync the same way toggle_staged_view and
render.create already do, and cover it with an E2E case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant