Skip to content

Commit 087b634

Browse files
xyb3rtmcepl
authored andcommitted
Prevent moving space from closed wins into guide wins
We now use the WinClosed autocmd for this which means that it also happens when using builtin vim functionality to close the window.
1 parent 28466bf commit 087b634

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

plugin/acme.vim

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,6 @@ function s:MoveWin(w, other, below)
723723
noa exe win_id2win(p != a:w ? p : nw).'wincmd w'
724724
noa exe win_id2win(w != a:w ? w : nw).'wincmd w'
725725
noa exe win_id2win(a:w).'close!'
726-
call remove(col, i)
727-
call s:Layout(col)
728-
call s:Layout(s:WinCol(nw))
729726
endif
730727
endfunc
731728

@@ -741,8 +738,6 @@ function s:NewCol(w)
741738
noa exe win_id2win(p).'wincmd w'
742739
noa exe win_id2win(w).'wincmd w'
743740
noa exe win_id2win(a:w).'close!'
744-
call remove(col, index(col, a:w))
745-
call s:Layout(col)
746741
endfunc
747742

748743
function s:Scroll(topline)
@@ -1177,18 +1172,32 @@ function s:BufWinLeave()
11771172
endif
11781173
endfunc
11791174

1180-
function s:WinClosed(w)
1181-
if has_key(s:minimized, a:w)
1182-
call remove(s:minimized, a:w)
1175+
function s:WinClosedPre()
1176+
" Only works with 'nosplitbelow'
1177+
let w = expand("<amatch>")
1178+
let h = winheight(w) + 1
1179+
let col = s:WinCol(w)
1180+
let [i, j] = [index(col, w), index(col, win_getid())]
1181+
if j == -1
1182+
let fbelow = i + 1 == len(col) ? '' :
1183+
\ fnamemodify(bufname(winbufnr(col[i + 1])), ':t')
1184+
if i == 0 || fbelow != 'guide'
1185+
return
1186+
endif
1187+
let j = i - 1
11831188
endif
1184-
let col = s:WinCol(a:w)
1185-
call remove(col, index(col, a:w))
1186-
call timer_start(0, {_ -> s:Layout(col)})
1189+
let focus = w == win_getid()
1190+
call timer_start(0, {_ -> s:WinClosedPost(col[j], i - j, h, focus)})
11871191
endfunc
11881192

1189-
function s:WinNew(w)
1190-
let col = s:WinCol(a:w)
1191-
call timer_start(0, {_ -> s:Layout(col)})
1193+
function s:WinClosedPost(w, n, h, focus)
1194+
let w = win_id2win(a:w)
1195+
for i in a:n < 0 ? range(a:n + 1, -1) : reverse(range(a:n))
1196+
call win_move_statusline(w + i, a:n < 0 ? -a:h : a:h)
1197+
endfor
1198+
if a:focus
1199+
exe w.'wincmd w'
1200+
endif
11921201
endfunc
11931202

11941203
augroup acme_vim
@@ -1200,8 +1209,7 @@ au TextChanged,TextChangedI guide setl nomodified
12001209
au VimEnter * call s:ReloadDirs(winnr())
12011210
au VimResized * call s:ReloadDirs(0)
12021211
au WinResized * call s:ReloadDirs(0)
1203-
au WinClosed * call s:WinClosed(str2nr(expand("<amatch>")))
1204-
au WinNew * call s:WinNew(win_getid())
1212+
au WinClosed * call s:WinClosedPre()
12051213
augroup END
12061214

12071215
if exists("s:ctrlexe")

0 commit comments

Comments
 (0)