Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to disable tmux navigation when zoomed #41

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
```

Expand Down
4 changes: 4 additions & 0 deletions lua/smart-splits/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/smart-splits/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local M = {
'WinEnter',
},
tmux_integration = true,
disable_tmux_nav_when_zoomed = true,
}

local function default_bool(value, default)
Expand Down
21 changes: 21 additions & 0 deletions lua/smart-splits/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down