diff --git a/autoload/flog/floggraph/side_win.vim b/autoload/flog/floggraph/side_win.vim index 48ef764..6f9ebc5 100644 --- a/autoload/flog/floggraph/side_win.vim +++ b/autoload/flog/floggraph/side_win.vim @@ -63,6 +63,12 @@ function! flog#floggraph#side_win#Open(cmd, keep_focus, is_tmp) abort let l:graph_win = flog#win#Save() let l:saved_win_ids = flog#win#GetAllIds() + " See below + let l:saved_sizes = {} + if !&equalalways + let l:saved_sizes = flog#win#SaveSizes(l:saved_win_ids) + endif + exec a:cmd let l:final_win = flog#win#Save() @@ -73,9 +79,19 @@ function! flog#floggraph#side_win#Open(cmd, keep_focus, is_tmp) abort call flog#win#Restore(l:graph_win) if a:is_tmp + " Lock unchanged windows to only equalize what is necessary + if !&equalalways + call flog#win#LockUnchangedSavedSizes(l:saved_sizes) + endif + call flog#floggraph#side_win#CloseTmp() + + " Equalize select windows. Ideally we could set window sizes to what + " they *would* be if temp windows were closed first, but this is a hard + " problem if !&equalalways - wincmd = + tabdo wincmd = + call flog#win#UnlockSavedSizes(l:saved_sizes) endif endif diff --git a/autoload/flog/win.vim b/autoload/flog/win.vim index 22f0f25..d2d0f6d 100644 --- a/autoload/flog/win.vim +++ b/autoload/flog/win.vim @@ -89,3 +89,52 @@ function! flog#win#RestoreVcol(saved_win) abort call flog#win#SetVcol('.', l:vcol) return l:vcol endfunction + +function! flog#win#SaveSizes(windows) abort + let l:sizes = {} + for l:window in a:windows + let l:tabwin = win_id2tabwin(l:window) + if l:tabwin == [0, 0] + continue + endif + + let l:sizes[l:window] = [ + \ winwidth(l:window), + \ winheight(l:window), + \ gettabwinvar(l:tabwin[0], l:tabwin[1], '&winfixwidth'), + \ gettabwinvar(l:tabwin[0], l:tabwin[1], '&winfixheight')] + endfor + return sizes +endfunction + +function! flog#win#LockUnchangedSavedSizes(saved_sizes) abort + for l:window in keys(a:saved_sizes) + if !has_key(a:saved_sizes, l:window) + continue + endif + + let l:tabwin = win_id2tabwin(l:window) + if l:tabwin == [0, 0] + continue + endif + + if a:saved_sizes[l:window][0] == winwidth(l:window) + call settabwinvar(l:tabwin[0], l:tabwin[1], '&winfixwidth', 1) + endif + if a:saved_sizes[l:window][1] == winheight(l:window) + call settabwinvar(l:tabwin[0], l:tabwin[1], '&winfixheight', 1) + endif + endfor +endfunction + +function! flog#win#UnlockSavedSizes(saved_sizes) abort + for l:window in keys(a:saved_sizes) + let l:tabwin = win_id2tabwin(l:window) + if l:tabwin == [0, 0] + continue + endif + + call settabwinvar(l:tabwin[0], l:tabwin[1], '&winfixwidth', a:saved_sizes[l:window][2]) + call settabwinvar(l:tabwin[0], l:tabwin[1], '&winfixheight', a:saved_sizes[l:window][3]) + endfor +endfunction