Add Comments
1 file changed, 7 insertions(+), 1 deletion(-)
@@ -1,5 +1,6 @@
local M = {}
-- Modes
local MODE = {
WINDOW = "window",
TAB = "tab",
@@ -11,7 +12,7 @@
left = "h",
right = "l",
}
-- Run zellij action safely
local function zellij_action(args)
vim.fn.system("zellij action " .. args)
if vim.v.shell_error ~= 0 then
@@ -19,24 +20,29 @@
end
end
-- Try vim window move, fallback to zellij
local function navigate(direction, vim_key, fallback)
local before = vim.fn.winnr()
vim.cmd("wincmd " .. vim_key)
local after = vim.fn.winnr()
-- If vim didn't move, fallback to zellij
if before == after then
zellij_action(fallback .. " " .. direction)
end
end
-- Window navigation
function M.move(direction)
navigate(direction, direction_translation[direction], "move-focus")
end
-- Window navigation or tab switch
function M.move_or_tab(direction)
navigate(direction, direction_translation[direction], "move-focus-or-tab")
end
-- Setup user commands
function M.setup()
vim.api.nvim_create_user_command("ZellijUp", function() M.move("up") end, {})
vim.api.nvim_create_user_command("ZellijDown", function() M.move("down") end, {})