fix: add open_float params to toggle_float (#716)
* feat: `toggle_float` now takes the same params as `open_float` * docs: update `toggle_float` docs for `opts` and `cb` params * fix: ensure cb is always called --------- Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com>
This commit is contained in:
parent
6b59a6cf62
commit
7a09f0b000
3 changed files with 22 additions and 10 deletions
|
|
@ -394,7 +394,7 @@ These are plugins maintained by other authors that extend the functionality of o
|
||||||
- [toggle_hidden()](doc/api.md#toggle_hidden)
|
- [toggle_hidden()](doc/api.md#toggle_hidden)
|
||||||
- [get_current_dir(bufnr)](doc/api.md#get_current_dirbufnr)
|
- [get_current_dir(bufnr)](doc/api.md#get_current_dirbufnr)
|
||||||
- [open_float(dir, opts, cb)](doc/api.md#open_floatdir-opts-cb)
|
- [open_float(dir, opts, cb)](doc/api.md#open_floatdir-opts-cb)
|
||||||
- [toggle_float(dir)](doc/api.md#toggle_floatdir)
|
- [toggle_float(dir, opts, cb)](doc/api.md#toggle_floatdir)
|
||||||
- [open(dir, opts, cb)](doc/api.md#opendir-opts-cb)
|
- [open(dir, opts, cb)](doc/api.md#opendir-opts-cb)
|
||||||
- [close(opts)](doc/api.md#closeopts)
|
- [close(opts)](doc/api.md#closeopts)
|
||||||
- [open_preview(opts, callback)](doc/api.md#open_previewopts-callback)
|
- [open_preview(opts, callback)](doc/api.md#open_previewopts-callback)
|
||||||
|
|
|
||||||
21
doc/api.md
21
doc/api.md
|
|
@ -11,7 +11,7 @@
|
||||||
- [toggle_hidden()](#toggle_hidden)
|
- [toggle_hidden()](#toggle_hidden)
|
||||||
- [get_current_dir(bufnr)](#get_current_dirbufnr)
|
- [get_current_dir(bufnr)](#get_current_dirbufnr)
|
||||||
- [open_float(dir, opts, cb)](#open_floatdir-opts-cb)
|
- [open_float(dir, opts, cb)](#open_floatdir-opts-cb)
|
||||||
- [toggle_float(dir)](#toggle_floatdir)
|
- [toggle_float(dir, opts, cb)](#toggle_floatdir)
|
||||||
- [open(dir, opts, cb)](#opendir-opts-cb)
|
- [open(dir, opts, cb)](#opendir-opts-cb)
|
||||||
- [close(opts)](#closeopts)
|
- [close(opts)](#closeopts)
|
||||||
- [open_preview(opts, callback)](#open_previewopts-callback)
|
- [open_preview(opts, callback)](#open_previewopts-callback)
|
||||||
|
|
@ -107,14 +107,21 @@ Open oil browser in a floating window
|
||||||
| >>split | `nil\|"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier |
|
| >>split | `nil\|"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier |
|
||||||
| cb | `nil\|fun()` | Called after the oil buffer is ready |
|
| cb | `nil\|fun()` | Called after the oil buffer is ready |
|
||||||
|
|
||||||
## toggle_float(dir)
|
## toggle_float(dir, opts, cb)
|
||||||
|
|
||||||
`toggle_float(dir)` \
|
`toggle_float(dir, opts, cb)` \
|
||||||
Open oil browser in a floating window, or close it if open
|
Open oil browser in a floating window, or close it if open. Parameters only apply when the floating window is
|
||||||
|
opened
|
||||||
|
|
||||||
| Param | Type | Desc |
|
| Param | Type | Desc |
|
||||||
| ----- | ------------- | ------------------------------------------------------------------------------------------- |
|
| ------------ | ------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
||||||
| dir | `nil\|string` | When nil, open the parent of the current buffer, or the cwd if current buffer is not a file |
|
| dir | `nil\|string` | When nil, open the parent of the current buffer, or the cwd if current buffer is not a file |
|
||||||
|
| opts | `nil\|oil.OpenOpts` | |
|
||||||
|
| >preview | `nil\|oil.OpenPreviewOpts` | When present, open the preview window after opening oil |
|
||||||
|
| >>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"` | Split modifier |
|
||||||
|
| cb | `nil\|fun()` | Called after the oil buffer is ready |
|
||||||
|
|
||||||
## open(dir, opts, cb)
|
## open(dir, opts, cb)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -342,11 +342,16 @@ end
|
||||||
|
|
||||||
---Open oil browser in a floating window, or close it if open
|
---Open oil browser in a floating window, or close it if open
|
||||||
---@param dir nil|string When nil, open the parent of the current buffer, or the cwd if current buffer is not a file
|
---@param dir nil|string When nil, open the parent of the current buffer, or the cwd if current buffer is not a file
|
||||||
M.toggle_float = function(dir)
|
---@param opts? oil.OpenOpts
|
||||||
|
---@param cb? fun() Called after the oil buffer is ready
|
||||||
|
M.toggle_float = function(dir, opts, cb)
|
||||||
if vim.w.is_oil_win then
|
if vim.w.is_oil_win then
|
||||||
M.close()
|
M.close()
|
||||||
|
if cb then
|
||||||
|
cb()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
M.open_float(dir)
|
M.open_float(dir, opts, cb)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue