From 7a09f0b000e8dae148e4267927d9aad4e3926434 Mon Sep 17 00:00:00 2001 From: zeta-squared <84503911+zeta-squared@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:01:02 +1100 Subject: [PATCH] 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> --- README.md | 2 +- doc/api.md | 21 ++++++++++++++------- lua/oil/init.lua | 9 +++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 321bdba..8e0dba0 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/doc/api.md b/doc/api.md index f4577c4..7a10791 100644 --- a/doc/api.md +++ b/doc/api.md @@ -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) @@ -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) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 0c56720..908d6dd 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -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