Skip to content

Commit 2843ba6

Browse files
committed
feat(config): add "auto" position option for panels (sindrets#536)
Add support for position = "auto" in file_panel.win_config which respects vim's splitright/splitbelow options when determining panel placement. Users can set this to have the panel position follow their vim split preferences.
1 parent ef57357 commit 2843ba6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lua/diffview/ui/panel.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,17 @@ function Panel:open()
269269
local config = self:get_config()
270270

271271
if config.type == "split" then
272-
local split_dir = vim.tbl_contains({ "top", "left" }, config.position) and "aboveleft" or "belowright"
272+
-- Resolve "auto" position based on vim's splitright/splitbelow options.
273+
local position = config.position
274+
if position == "auto" then
275+
if self.state.form == "row" then
276+
position = vim.o.splitbelow and "bottom" or "top"
277+
else
278+
position = vim.o.splitright and "right" or "left"
279+
end
280+
end
281+
282+
local split_dir = vim.tbl_contains({ "top", "left" }, position) and "aboveleft" or "belowright"
273283
local split_cmd = self.state.form == "row" and "sp" or "vsp"
274284
local rel_winid = config.relative == "win"
275285
and api.nvim_win_is_valid(config.win or -1)
@@ -282,7 +292,7 @@ function Panel:open()
282292
api.nvim_win_set_buf(self.winid, self.bufid)
283293

284294
if config.relative == "editor" then
285-
local dir = ({ left = "H", bottom = "J", top = "K", right = "L" })[config.position]
295+
local dir = ({ left = "H", bottom = "J", top = "K", right = "L" })[position]
286296
vim.cmd("wincmd " .. dir)
287297
vim.cmd("wincmd =")
288298
end

0 commit comments

Comments
 (0)