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.
This commit is contained in:
parent
abc4879688
commit
385bd82ce3
2 changed files with 29 additions and 0 deletions
|
|
@ -479,6 +479,21 @@ close({opts}) *canola.c
|
||||||
{exit_if_last_buf} `nil|boolean` Exit vim if this canola buffer is the
|
{exit_if_last_buf} `nil|boolean` Exit vim if this canola buffer is the
|
||||||
last open buffer
|
last open buffer
|
||||||
|
|
||||||
|
toggle({dir}, {opts}, {cb}) *canola.toggle*
|
||||||
|
Open canola browser for a directory, or close it if already open
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
{dir} `nil|string` When nil, open the parent of the current buffer, or
|
||||||
|
the cwd if current buffer is not a file
|
||||||
|
{opts} `nil|canola.OpenOpts`
|
||||||
|
{preview} `nil|canola.OpenPreviewOpts` When present, open the preview
|
||||||
|
window after opening canola
|
||||||
|
{vertical} `nil|boolean` Open the buffer in a vertical split
|
||||||
|
{horizontal} `nil|boolean` Open the buffer in a horizontal split
|
||||||
|
{split} `nil|"aboveleft"|"belowright"|"topleft"|"botright"` S
|
||||||
|
plit modifier
|
||||||
|
{cb} `nil|fun()` Called after the canola buffer is ready
|
||||||
|
|
||||||
open_preview({opts}, {callback}) *canola.open_preview*
|
open_preview({opts}, {callback}) *canola.open_preview*
|
||||||
Preview the entry under the cursor in a split
|
Preview the entry under the cursor in a split
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -526,6 +526,20 @@ M.close = function(opts)
|
||||||
vim.api.nvim_buf_delete(canolabuf, { force = true })
|
vim.api.nvim_buf_delete(canolabuf, { force = true })
|
||||||
end
|
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
|
---@class canola.OpenPreviewOpts
|
||||||
---@field vertical? boolean Open the buffer in a vertical split
|
---@field vertical? boolean Open the buffer in a vertical split
|
||||||
---@field horizontal? boolean Open the buffer in a horizontal split
|
---@field horizontal? boolean Open the buffer in a horizontal split
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue