refactor(git): rebuild status_view diff layout per selection
This commit is contained in:
@@ -39,16 +39,28 @@ local function find_sidebar()
|
||||
end
|
||||
end
|
||||
|
||||
---Find a diff-role window in the given tabpage (or current).
|
||||
---Find a diff window in the given tabpage (or current). "left" / "right"
|
||||
---is determined by column position: the layout is [sidebar | left | right],
|
||||
---so the leftmost &diff window is the left pane and the rightmost is the
|
||||
---right pane.
|
||||
---@param role "left"|"right"
|
||||
---@param tab integer?
|
||||
---@return integer?
|
||||
local function find_diff_win(role, tab)
|
||||
local diffs = {}
|
||||
for _, w in ipairs(vim.api.nvim_tabpage_list_wins(tab or 0)) do
|
||||
if vim.w[w].git_diff_role == role then
|
||||
return w
|
||||
if vim.wo[w].diff then
|
||||
table.insert(diffs, w)
|
||||
end
|
||||
end
|
||||
table.sort(diffs, function(a, b)
|
||||
return vim.api.nvim_win_get_position(a)[2]
|
||||
< vim.api.nvim_win_get_position(b)[2]
|
||||
end)
|
||||
if role == "left" then
|
||||
return diffs[1]
|
||||
end
|
||||
return diffs[#diffs]
|
||||
end
|
||||
|
||||
---@param file_path string
|
||||
@@ -161,7 +173,6 @@ t.test(
|
||||
setup_sidebar_with_unstaged_file("foo.txt", "v1\n", "v2\n")
|
||||
local tab1 = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
-- First show diff in tab1, so state.diff_*_win point at tab1.
|
||||
vim.api.nvim_set_current_win(sidebar_win)
|
||||
vim.api.nvim_win_set_cursor(sidebar_win, { line, 0 })
|
||||
t.press("<Tab>")
|
||||
|
||||
Reference in New Issue
Block a user