From 2bc42accec90cd069042199c3a93a8d60013f6d1 Mon Sep 17 00:00:00 2001 From: Shi Han NG Date: Thu, 11 Jul 2024 21:04:45 +0900 Subject: [PATCH] Allow move-focus-or-tab as action --- lua/zellij-nav/init.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lua/zellij-nav/init.lua b/lua/zellij-nav/init.lua index 6777de1..d96e41b 100644 --- a/lua/zellij-nav/init.lua +++ b/lua/zellij-nav/init.lua @@ -1,6 +1,12 @@ local M = {} -local function nav(short_direction, direction) +local function nav(short_direction, direction, action) + action = action or "move-focus" + + if action ~= "move-focus" and action ~= "move-focus-or-tab" then + error("invalid action: " .. action) + end + -- get window ID, try switching windows, and get ID again to see if it worked local cur_winnr = vim.fn.winnr() vim.api.nvim_command("wincmd " .. short_direction) @@ -8,27 +14,27 @@ local function nav(short_direction, direction) -- if the window ID didn't change, then we didn't switch if cur_winnr == new_winnr then - vim.fn.system("zellij action move-focus " .. direction) + vim.fn.system("zellij action " .. action .. " " .. direction) if vim.v.shell_error ~= 0 then error("zellij executable not found in path") end end end -function M.up() - nav("k", "up") +function M.up(action) + nav("k", "up", action) end -function M.down() - nav("j", "down") +function M.down(action) + nav("j", "down", action) end -function M.right() - nav("l", "right") +function M.right(action) + nav("l", "right", action) end -function M.left() - nav("h", "left") +function M.left(action) + nav("h", "left", action) end -- create our exported setup() function