diff --git a/packages/nvim/config/lua/hjdivad_util/tmux.lua b/packages/nvim/config/lua/hjdivad_util/tmux.lua index bc99cc8..8ce62f2 100644 --- a/packages/nvim/config/lua/hjdivad_util/tmux.lua +++ b/packages/nvim/config/lua/hjdivad_util/tmux.lua @@ -109,6 +109,20 @@ function M._selection_string_to_pane_info(selection) return pane_info end +---@param selected string[] +---@param opts GotoFzfTmuxSessionOptions +function M._fzf_lua_action_default(selected, opts) + if #selected == 0 then + return + end + + local pane_info = M._selection_string_to_pane_info(selected[1]) + M.goto_tmux_session(pane_info.session_name, pane_info.window_name) + + if opts.quit_on_selection then + vim.cmd('quitall') + end +end ---@class GotoFzfTmuxSessionOptions ---@field quit_on_selection boolean | nil @@ -136,12 +150,7 @@ function M.goto_fzf_tmux_session(options) actions = { ---@param selected string[] ['default'] = function (selected, _) - local pane_info = M._selection_string_to_pane_info(selected[1]) - M.goto_tmux_session(pane_info.session_name, pane_info.window_name) - - if opts.quit_on_selection then - vim.cmd('quitall') - end + M._fzf_lua_action_default(selected, opts) end } }) diff --git a/tests/hjdivad_util/tmux_spec.lua b/tests/hjdivad_util/tmux_spec.lua index 2128728..cee50f1 100644 --- a/tests/hjdivad_util/tmux_spec.lua +++ b/tests/hjdivad_util/tmux_spec.lua @@ -50,4 +50,12 @@ describe("tmux", function() }, tmux.get_tmux_panes({ socket_name = "tmux_spec" }), "get_tmux_panes can read tmux list-panes") end) end) + + describe("_fzf_lua_action_default", function() + it("exits without errors when selected is empty", function() + assert.has_no.errors(function() + tmux._fzf_lua_action_default({}, {}) + end) + end) + end) end)