From 5ca83b6f39aeea698b5db78df594ed7c02ee230f Mon Sep 17 00:00:00 2001 From: rbong Date: Tue, 20 Aug 2024 14:11:22 -0400 Subject: [PATCH 1/2] Equalize window sizes only when necessary --- autoload/flog/floggraph/side_win.vim | 16 +++++++++ autoload/flog/win.vim | 49 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/autoload/flog/floggraph/side_win.vim b/autoload/flog/floggraph/side_win.vim index 48ef764..3654b0b 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 = + 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 From 658f9889435442c78493ccbae1fd7ffc212bec8a Mon Sep 17 00:00:00 2001 From: rbong Date: Tue, 20 Aug 2024 14:13:42 -0400 Subject: [PATCH 2/2] Equalize windows all tabs when opening temp wins --- autoload/flog/floggraph/side_win.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/flog/floggraph/side_win.vim b/autoload/flog/floggraph/side_win.vim index 3654b0b..6f9ebc5 100644 --- a/autoload/flog/floggraph/side_win.vim +++ b/autoload/flog/floggraph/side_win.vim @@ -90,7 +90,7 @@ function! flog#floggraph#side_win#Open(cmd, keep_focus, is_tmp) abort " 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