refactor(git): pull buffer-placement tail into util.place_buf
This commit is contained in:
+19
-8
@@ -41,6 +41,24 @@ function M.parse_revspec(revspec)
|
||||
return { stage = nil, path = path }
|
||||
end
|
||||
|
||||
---Place a buffer in the current window or a new split per `split`.
|
||||
---`false` replaces the current buffer (drops a `'` mark first so `''`
|
||||
---jumps back); a direction string opens a leftabove split; nil falls
|
||||
---back to a `splitbelow`-aware horizontal split.
|
||||
---@param buf integer
|
||||
---@param split (false|"above"|"below"|"left"|"right")?
|
||||
---@return integer win
|
||||
function M.place_buf(buf, split)
|
||||
if split == false then
|
||||
vim.cmd.normal({ "m'", bang = true })
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
return vim.api.nvim_get_current_win()
|
||||
end
|
||||
return vim.api.nvim_open_win(buf, true, {
|
||||
split = split or (vim.o.splitbelow and "below" or "above"),
|
||||
})
|
||||
end
|
||||
|
||||
---@class ow.Git.NewScratchOpts
|
||||
---@field name string?
|
||||
---@field bufhidden ("hide"|"wipe")? defaults to "hide"
|
||||
@@ -63,14 +81,7 @@ function M.new_scratch(opts)
|
||||
if opts.name then
|
||||
pcall(vim.api.nvim_buf_set_name, buf, opts.name)
|
||||
end
|
||||
if opts.split == false then
|
||||
vim.cmd.normal({ "m'", bang = true })
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
return buf, vim.api.nvim_get_current_win()
|
||||
end
|
||||
local split = opts.split or (vim.o.splitbelow and "below" or "above")
|
||||
local win = vim.api.nvim_open_win(buf, true, { split = split })
|
||||
return buf, win
|
||||
return buf, M.place_buf(buf, opts.split)
|
||||
end
|
||||
|
||||
---@param fmt string
|
||||
|
||||
Reference in New Issue
Block a user