Skip to content

Commit

Permalink
Merge branch 'master' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
rbong committed Aug 20, 2024
2 parents bc2fce2 + 658f988 commit 9d9fd51
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
18 changes: 17 additions & 1 deletion autoload/flog/floggraph/side_win.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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

Expand Down
49 changes: 49 additions & 0 deletions autoload/flog/win.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9d9fd51

Please sign in to comment.