feat: add toggle() API for regular windows (#88)
* feat: add `toggle()` API for regular windows Problem: `toggle_float()` and `toggle_split()` exist but there is no `toggle()` for regular windows, forcing users to write their own filetype-checking wrapper. Solution: add `M.toggle()` that delegates to `close()` or `open()` based on whether the current buffer is a canola buffer. Includes vimdoc entry. * docs(upstream): mark #621 fixed
This commit is contained in:
parent
fc43684bbd
commit
94db584f81
3 changed files with 31 additions and 1 deletions
|
|
@ -526,6 +526,20 @@ M.close = function(opts)
|
|||
vim.api.nvim_buf_delete(canolabuf, { force = true })
|
||||
end
|
||||
|
||||
---@param dir? string
|
||||
---@param opts? canola.OpenOpts
|
||||
---@param cb? fun()
|
||||
M.toggle = function(dir, opts, cb)
|
||||
if vim.w.is_canola_win or vim.bo.filetype == 'canola' then
|
||||
M.close()
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
else
|
||||
M.open(dir, opts, cb)
|
||||
end
|
||||
end
|
||||
|
||||
---@class canola.OpenPreviewOpts
|
||||
---@field vertical? boolean Open the buffer in a vertical split
|
||||
---@field horizontal? boolean Open the buffer in a horizontal split
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue