From 315848dda818335adf19e08f28ababae873ff2a9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 15 Jun 2016 22:47:07 +0200 Subject: [PATCH] Prevent zooming out of tmux pane There were issues (e.g. #56) and pull requests (#65 and #104) to improve this behavior, but they were mainly rejected because it breaks other use cases. This PR adds an option that can be enabled to have the current behavior (`let g:tmux_navigator_move_out_of_zoomed_tmux = 1`) by default, but it also recognizes when the user tries to get out of the zoomed pane twice, and then allows for it. --- plugin/tmux_navigator.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugin/tmux_navigator.vim b/plugin/tmux_navigator.vim index b58601e..b3ee279 100644 --- a/plugin/tmux_navigator.vim +++ b/plugin/tmux_navigator.vim @@ -79,6 +79,27 @@ function! s:TmuxAwareNavigate(direction) endtry endif let args = 'select-pane -t ' . shellescape($TMUX_PANE) . ' -' . tr(a:direction, 'phjkl', 'lLDUR') + + " Handle delay for moving out of zoomed tmux pane. + " This wraps the tmux args conditionally. + let timeout = get(g:, 'tmux_navigator_zoomed_tmux_delay', 0.5) + if timeout != 0 + let msg = 'Tmux is zoomed, not moving out.' + let curtime = reltimefloat(reltime()) + if (a:direction != s:tried_moving_out_of_zoomed_tmux[0] + \ || curtime > (s:tried_moving_out_of_zoomed_tmux[1] + timeout)) + " 0 to zoom out always + " -1 can be used to never zoom out. + let msg .= printf(' Trigger it again in %.1f seconds to zoom out.', + \ timeout) + let msg .= ' See the help for g:tmux_navigator_zoomed_tmux_delay.' + let s:tried_moving_out_of_zoomed_tmux = [a:direction, curtime] + let args = "if -F '#{window_zoomed_flag}' 'display \"".msg."\"'" + \ ." '".args."'" + else + let s:tried_moving_out_of_zoomed_tmux = ['', 0] + endif + endif silent call s:TmuxCommand(args) if s:NeedsVitalityRedraw() redraw! @@ -88,6 +109,7 @@ function! s:TmuxAwareNavigate(direction) let s:tmux_is_last_pane = 0 endif endfunction +let s:tried_moving_out_of_zoomed_tmux = ['', 0] function! s:VimNavigate(direction) try