@@ -46,13 +46,13 @@ endfunction
4646" }}}
4747" accordion#Start(size) set global accordion size and trigger layout {{{
4848function ! accordion#Start (size)
49- let g: accordion_size = a: size
49+ call s: SetSize ( g: , a: size)
5050 call accordion#Accordion ()
5151endfunction
5252" }}}
5353" accordion#StartTab(size) set tab accordion size and trigger layout {{{
5454function ! accordion#StartTab (size)
55- let t :accordion_size = a: size
55+ call s: SetSize ( t :, a: size)
5656 call accordion#Accordion ()
5757endfunction
5858" }}}
@@ -100,14 +100,15 @@ function! accordion#ChangeSize(change)
100100 " change tab variable if it exists
101101 if exists (" t:accordion_size" )
102102 if t :accordion_size + a: change >= 1
103- let t : accordion_size += a: change
103+ call s: SetSize ( t :, t : accordion_size + a: change)
104104 call accordion#Accordion ()
105105 else
106106 echoerr " Accordion size can't be less than 1"
107107 endif
108108 " else change global if it exists
109109 elseif exists (" g:accordion_size" )
110110 if g: accordion_size + a: change >= 1
111+ call s: SetSize (g: , g: accordion_size + a: change )
111112 let g: accordion_size += a: change
112113 call accordion#Accordion ()
113114 else
@@ -129,6 +130,17 @@ function! accordion#Unpause()
129130 let s: accordion_running = 0
130131endfunction
131132" }}}
133+ " Helpers:
134+ " s:SetSize(ns, size) set global or tab size. If already set, also mark g:accordion_size_changed {{{
135+ " If accordion was running and the user called it again with a different size,
136+ " we need to re-layout.
137+ function ! s: SetSize (ns, size)
138+ if get (a: ns , " accordion_size" )
139+ let g: accordion_size_changed= 1
140+ endif
141+ let a: ns [" accordion_size" ]= a: size
142+ endfunction
143+ " }}}
132144" Shrinking:
133145" s:WindowIsShrunk() returns true if current window is shrunk {{{
134146function ! s: WindowIsShrunk ()
@@ -292,6 +304,15 @@ function! s:GetDesiredViewport(size, direction)
292304 let resized_viewport = {}
293305 let should_redraw = 1
294306 let dir = a: direction [" direction" ]
307+ let magnitude = a: direction [" magnitude" ]
308+ if exists (" g:accordion_size_changed" )
309+ let size_changed = 1
310+ let dir = " h"
311+ let magnitude = 0
312+ unlet g: accordion_size_changed
313+ else
314+ let size_changed = 0
315+ endif
295316 " initially set viewport to show windows to the right of curwin
296317 if ! exists (" t:accordion_last_desired_viewport" )
297318 let desired_viewport[" h" ] = 0
@@ -305,15 +326,15 @@ function! s:GetDesiredViewport(size, direction)
305326 elseif dir == " h" || dir == " l"
306327 let desired_viewport = t :accordion_last_desired_viewport
307328 let desired_viewport[dir ] =
308- \ max ([desired_viewport[dir ] - a: direction [ " magnitude" ], 0 ] )
329+ \ max ([desired_viewport[dir ] - magnitude)
309330 let desired_viewport[s: opposites [dir ]] =
310- \ min ([desired_viewport[s: opposites [dir ]] + a: direction [ " magnitude" ] , a: size - 1 ])
331+ \ min ([desired_viewport[s: opposites [dir ]] + magnitude, a: size - 1 ])
311332 " if the current window's not shrunk, there's no need to redraw
312333 " we skip redrawing to be more efficient and to let users resize the
313334 " visible splits
314335 " If the user's just called :vsp and added a new window, we still need to
315336 " redraw
316- if ! s: WindowIsShrunk () && winnr (" $" ) == get (t :, " accordion_num_windows" )
337+ if ! s: WindowIsShrunk () && winnr (" $" ) == get (t :, " accordion_num_windows" ) && ! size_changed
317338 let should_redraw = 0
318339 endif
319340 endif
0 commit comments