Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ These are plugins maintained by other authors that extend the functionality of o
- [toggle_hidden()](doc/api.md#toggle_hidden)
- [get_current_dir(bufnr)](doc/api.md#get_current_dirbufnr)
- [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)
- [close(opts)](doc/api.md#closeopts)
- [open_preview(opts, callback)](doc/api.md#open_previewopts-callback)
Expand Down
21 changes: 14 additions & 7 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [toggle_hidden()](#toggle_hidden)
- [get_current_dir(bufnr)](#get_current_dirbufnr)
- [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)
- [close(opts)](#closeopts)
- [open_preview(opts, callback)](#open_previewopts-callback)
Expand Down Expand Up @@ -107,14 +107,21 @@ Open oil browser in a floating window
| >>split | `nil\|"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier |
| cb | `nil\|fun()` | Called after the oil buffer is ready |

## toggle_float(dir)
## toggle_float(dir, opts, cb)

`toggle_float(dir)` \
Open oil browser in a floating window, or close it if open
`toggle_float(dir, opts, cb)` \
Open oil browser in a floating window, or close it if open. Parameters only apply when the floating window is
opened

| 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 |
| 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 |
| 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)

Expand Down
9 changes: 7 additions & 2 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,16 @@ end

---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
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
M.close()
if cb then
cb()
end
else
M.open_float(dir)
M.open_float(dir, opts, cb)
end
end

Expand Down