From 91c4b8007ecf937ce750748dffe4fcfbbf4d5785 Mon Sep 17 00:00:00 2001 From: Marcus Gasberg Date: Mon, 28 Sep 2026 12:47:27 +0200 Subject: [PATCH] fix(explorer): allow file navigation before a hidden explorer is first 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 --- lua/codediff/ui/explorer/actions.lua | 4 ++-- tests/e2e/explorer/actions_spec.lua | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lua/codediff/ui/explorer/actions.lua b/lua/codediff/ui/explorer/actions.lua index f06175d5..bfdf8859 100644 --- a/lua/codediff/ui/explorer/actions.lua +++ b/lua/codediff/ui/explorer/actions.lua @@ -58,7 +58,7 @@ function M.navigate_next(explorer) -- Update tree selection visually (switch to explorer window temporarily) local current_win = vim.api.nvim_get_current_win() - if vim.api.nvim_win_is_valid(explorer.winid) then + if explorer.winid and vim.api.nvim_win_is_valid(explorer.winid) then local line = find_node_line(explorer, next_file.data.path, next_file.data.group) if line then vim.api.nvim_set_current_win(explorer.winid) @@ -114,7 +114,7 @@ function M.navigate_prev(explorer) -- Update tree selection visually (switch to explorer window temporarily) local current_win = vim.api.nvim_get_current_win() - if vim.api.nvim_win_is_valid(explorer.winid) then + if explorer.winid and vim.api.nvim_win_is_valid(explorer.winid) then local line = find_node_line(explorer, prev_file.data.path, prev_file.data.group) if line then vim.api.nvim_set_current_win(explorer.winid) diff --git a/tests/e2e/explorer/actions_spec.lua b/tests/e2e/explorer/actions_spec.lua index e04744e2..6ec9f0c3 100644 --- a/tests/e2e/explorer/actions_spec.lua +++ b/tests/e2e/explorer/actions_spec.lua @@ -166,6 +166,16 @@ for _, backend in ipairs({ "native", "polling" }) do h.expect_text(screen, "modified", "working-A") end) + it("[E21] file navigation works while an initially hidden panel has never been shown", function() + screen:exec("require('codediff').setup({ explorer = { hidden = true } })") + open("CodeDiff -- a.txt b.txt") + h.action(screen, "view", "next_file", "modified") + h.expect_text(screen, "modified", "working-B") + h.idle(screen) + h.action(screen, "view", "prev_file", "modified") + h.expect_text(screen, "original", "index-A") + end) + it("[E13] pathspecs and ignore filters continue to apply after external changes", function() screen:exec("require('codediff').setup({ explorer = { file_filter = { ignore = { 'nested/**' } } } })") open("CodeDiff -- a.txt nested/alpha.txt")