From 39ac4f3d7d66b76b1471cd7034be25efe1215282 Mon Sep 17 00:00:00 2001 From: Mat Jones Date: Mon, 12 Dec 2022 08:06:12 -0500 Subject: [PATCH] add option to disable tmux navigation when zoomed --- README.md | 2 ++ lua/smart-splits/api.lua | 4 ++++ lua/smart-splits/config.lua | 1 + lua/smart-splits/tmux.lua | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 6533c89..879373c 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ require('smart-splits').setup({ }, -- enable or disable the tmux integration tmux_integration = true, + -- disable tmux navigation if current tmux pane is zoomed + disable_tmux_nav_when_zoomed = true, }) ``` diff --git a/lua/smart-splits/api.lua b/lua/smart-splits/api.lua index 087c902..59049b6 100644 --- a/lua/smart-splits/api.lua +++ b/lua/smart-splits/api.lua @@ -280,6 +280,10 @@ local function move_cursor_tmux(direction, at_edge_and_moving_to_edge) return false end + if config.disable_tmux_nav_when_zoomed and tmux.current_pane_is_zoomed() then + return false + end + local tmux_moved = move_tmux_inner(dir_key) if tmux_moved or not at_edge_and_moving_to_edge then return tmux_moved diff --git a/lua/smart-splits/config.lua b/lua/smart-splits/config.lua index 5096f80..31c0dae 100644 --- a/lua/smart-splits/config.lua +++ b/lua/smart-splits/config.lua @@ -24,6 +24,7 @@ local M = { 'WinEnter', }, tmux_integration = true, + disable_tmux_nav_when_zoomed = true, } local function default_bool(value, default) diff --git a/lua/smart-splits/tmux.lua b/lua/smart-splits/tmux.lua index e8fb3e2..a33c882 100644 --- a/lua/smart-splits/tmux.lua +++ b/lua/smart-splits/tmux.lua @@ -120,6 +120,27 @@ function M.current_pane_id() end end +function M.current_pane_is_zoomed() + local ok, is_zoomed = pcall(function() + -- '#F' format strings outputs pane creation flags, + -- if it it includes 'Z' then it's zoomed. A '*' indicates + -- current pane, and since we're only listing current pane flags, + -- we're expecting to see '*Z' if the current pane is zoomed + local output = tmux_exec("display-message -p '#F'") + if output then + output = vim.trim(output --[[@as string]]) + end + + return output == '*Z' + end) + + if ok then + return is_zoomed + else + return ok + end +end + ---Move to tmux pane directionally ---@param direction 'h'|'j'|'k'|'l' ---@return boolean true if command succeeded, false otherwise