From 9ef5180a6af60803695e8d3ecf4a5d483c0f8b8c Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Tue, 28 Apr 2026 07:35:09 +0200 Subject: [PATCH] fix(git): use :diffthis to keep diff state out of floating windows --- lua/git/diff.lua | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lua/git/diff.lua b/lua/git/diff.lua index adec5eb..3cceb8f 100644 --- a/lua/git/diff.lua +++ b/lua/git/diff.lua @@ -197,26 +197,19 @@ function M.set_buf_name_and_filetype(buf, name) end end ----Apply (or remove) the window-local options that `:diffthis` would ----normally set. Used by both `M.split` here and the sidebar so the two ----diff entry points behave consistently. Vim is supposed to save and ----restore these around the `'diff'` flag flip, but that round-trip is ----fragile when buffers are swapped under an already-diff window. +---Toggle a window into or out of Vim's diff mode. Goes through the +---`:diffthis` / `:diffoff` commands rather than `vim.wo[win].diff = X`. +---The command path runs Vim's full `diff_win_options` setup, which sets +---an internal flag that prevents subsequently-created floats from +---inheriting `'diff' = 1` when opened from a focused diff pane. The raw +---option setter skips that setup, so floats (oil, fzf-lua, etc) end up +---joining the tabpage's diff group and corrupting its render. ---@param win integer ---@param enabled boolean function M.set_diff(win, enabled) - vim.wo[win].diff = enabled - if enabled then - vim.wo[win].foldmethod = "diff" - vim.wo[win].foldenable = true - vim.wo[win].foldlevel = 0 - vim.wo[win].scrollbind = true - vim.wo[win].cursorbind = true - vim.wo[win].wrap = false - else - vim.wo[win].scrollbind = false - vim.wo[win].cursorbind = false - end + vim.api.nvim_win_call(win, function() + vim.cmd(enabled and "diffthis" or "diffoff") + end) end ---@class ow.Git.SplitOpts