Bug: explorer.focus_on_select = false ignored for added/untracked/deleted files in inline layout
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The focus leak comes from open_real_file in lua/codediff/ui/view/helpers.lua, which calls nvim_set_current_win before :edit and never restores the window. Compare with inline_view/update.lua, which saves and restores the current window in commit_update, and with inline_view/single_file.lua show_single_file, which does not. Done when selecting an added, untracked or deleted file with focus_on_select = false in inline layout leaves the cursor in the explorer; check by reproducing with the repro config in the issue.
Written by the indexing model from the issue text.
Description
Environment
- codediff.nvim v4.0.6
- Neovim v0.12.2 (macOS)
Description
With diff.layout = "inline", explorer.focus_on_select = false and auto_open_on_cursor = true,, selecting a
modified file in the explorer correctly keeps the cursor in the explorer, but
selecting an added, untracked or deleted file moves focus into the file
pane. Focus then stays there, so further j/k navigate the file instead of the
explorer. This doesn't seem to happen on every file though. I couldn't find a clear pattern in my testing.
Side-by-side layout is not affected.
Reproduction
-- repro.lua -> nvim -u repro.lua
local root = vim.fn.stdpath("data") .. "/site/pack/deps/start/lazy.nvim"
if not vim.loop.fs_stat(root) then
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", root })
end
vim.opt.rtp:prepend(root)
require("lazy").setup({
{
"esmuellert/codediff.nvim",
cmd = "CodeDiff",
opts = {
diff = { layout = "inline" },
explorer = {
auto_open_on_cursor = true,
focus_on_select = false,
},
},
},
}, { root = vim.fn.stdpath("data") .. "/repro/plugins" })
- In a repo with at least one file added relative to
main, run:CodeDiff main. - Move down the explorer with
juntil the cursor reaches the added file.
Expected: cursor stays in the explorer.
Actual: cursor jumps to the file pane and stays there.
Note that diff.layout = "inline" is required to reproduce. The bug does not occur
with the default side-by-side layout.
Suggested cause and fix by Claude
I don't dare create a vibe coded PR for this. This is the suggested cause and fix, that Claude created for me. The monkey-patched fix seems to work on my machine. I unfortunately don't have the time to look into this project and build a proper fix or verify this in detail. Still want to share it here, as it might be useful.
Cause
helpers.open_real_file (lua/codediff/ui/view/helpers.lua:162) calls
nvim_set_current_win(win) before :edit and never restores the previous window:
vim.api.nvim_set_current_win(win)
vim.cmd("edit " .. vim.fn.fnameescape(target))
Two callers in the inline layout:
inline_view/update.lua(modified files) savessaved_current_winand restores it
incommit_update, so the leaked focus change is undone.inline_view/single_file.lua:53(added/untracked/deleted files) does not, so the
focus change survives.
The side-by-side single-file path loads through helpers.show_real_file_buffer, which
never changes the current window — hence the layout-specific behaviour.
Suggested fix
Either save and restore the current window inside open_real_file itself, or mirror
update.lua's save/restore in inline_view/single_file.show_single_file.
- Dominant language
- Lua
- Stars
- 1.6k
- Forks
- 104
- Avg merge
- 16d 23h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from esmuellert/codediff.nvim
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
esmuellert/codediff.nvim#594 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
esmuellert/codediff.nvim#582 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
esmuellert/codediff.nvim#579 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
esmuellert/codediff.nvim#575 ·
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
esmuellert/codediff.nvim#565 · 1 comment ·
All issues in esmuellert/codediff.nvim
Similar issues
-
bug discord triage
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
AndyHazz/bookends.koplugin#134 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
coolsnowwolf/lede#14305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100