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
|
||||||
end
|
end
|
||||||
|
|
||||||
---Apply (or remove) the window-local options that `:diffthis` would
|
---Toggle a window into or out of Vim's diff mode. Goes through the
|
||||||
---normally set. Used by both `M.split` here and the sidebar so the two
|
---`:diffthis` / `:diffoff` commands rather than `vim.wo[win].diff = X`.
|
||||||
---diff entry points behave consistently. Vim is supposed to save and
|
---The command path runs Vim's full `diff_win_options` setup, which sets
|
||||||
---restore these around the `'diff'` flag flip, but that round-trip is
|
---an internal flag that prevents subsequently-created floats from
|
||||||
---fragile when buffers are swapped under an already-diff window.
|
---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 win integer
|
||||||
---@param enabled boolean
|
---@param enabled boolean
|
||||||
function M.set_diff(win, enabled)
|
function M.set_diff(win, enabled)
|
||||||
vim.wo[win].diff = enabled
|
vim.api.nvim_win_call(win, function()
|
||||||
if enabled then
|
vim.cmd(enabled and "diffthis" or "diffoff")
|
||||||
vim.wo[win].foldmethod = "diff"
|
end)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class ow.Git.SplitOpts
|
---@class ow.Git.SplitOpts
|
||||||
|
|||||||
Reference in New Issue
Block a user