fix(git): use :diffthis to keep diff state out of floating windows
This commit is contained in:
+10
-17
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user