Skip to content

Commit 1df2cda

Browse files
committed
Fix regression where changing sizes didn't redraw
fixes #30
1 parent 703ced4 commit 1df2cda

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Accordion lets you set the maximum number of vsplits you want to see, and shrink
77

88
If you want to view changes to a file over time, it's got a fancy diff mode. Even if you're not big on vsplits, you may want to consider Accordion for this feature alone.
99

10-
Version 0.5.1
10+
Version 0.5.2
1111

1212
But I Don't Use Splits!
1313
-----------------------

autoload/accordion.vim

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ endfunction
4646
"}}}
4747
"accordion#Start(size) set global accordion size and trigger layout {{{
4848
function! accordion#Start(size)
49-
let g:accordion_size = a:size
49+
call s:SetSize(g:, a:size)
5050
call accordion#Accordion()
5151
endfunction
5252
"}}}
5353
"accordion#StartTab(size) set tab accordion size and trigger layout {{{
5454
function! accordion#StartTab(size)
55-
let t:accordion_size = a:size
55+
call s:SetSize(t:, a:size)
5656
call accordion#Accordion()
5757
endfunction
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
130131
endfunction
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 {{{
134146
function! 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

Comments
 (0)