Skip to content

Commit

Permalink
optimization: Enable short-circuiting for zoom check in should_tmux_c…
Browse files Browse the repository at this point in the history
…ontrol

This change cuts out the `tmux` CLI invocation when
`disable_nav_when_zoomed = false`.

This reordering was necessary to enable this workaround because the
`and` operator is short-circuiting, and thus it will only evaluate the
RHS if the LHS is `true`. Before, the slow function call was the LHS,
and so it was being evaluated unconditionally, even when the
significantly faster boolean check would have failed.
  • Loading branch information
srithon committed Sep 1, 2024
1 parent dcfa4c5 commit 2b0bd6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ more:
possible workaround using `pgrep` (this might fail to work in some cases
though; if you do find such a case please open an issue).

If you are still having performance problems when switching panes inside of
Neovim, consider setting `disable_when_zoomed = false` in the configuration
for this plugin. When enabled, this config option causes
`nvim-tmux-navigation` to invoke the `tmux` CLI every time you switch panes;
disabling this switch circumvents this system call and makes switching panes
much faster!

3. Q: The plugin doesn't work when interacting with
[Poetry](https://python-poetry.org/) shells.
A: This happens because Poetry spawns sub-tty's, therefore messing with
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tmux-navigation/tmux_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

-- whether tmux should take control over the navigation
function util.should_tmux_control(is_same_winnr, disable_nav_when_zoomed)
if is_tmux_pane_zoomed() and disable_nav_when_zoomed then
if disable_nav_when_zoomed and is_tmux_pane_zoomed() then
return false
end
return is_same_winnr
Expand Down

0 comments on commit 2b0bd6c

Please sign in to comment.