@@ -685,23 +685,6 @@ function s:WinCol(w)
685685 return col
686686endfunc
687687
688- function s: CloseWin (w )
689- let h = winheight (a: w ) + 1
690- let col = s: WinCol (a: w )
691- let [i , j ] = [index (col , a: w ), index (col , win_getid ())]
692- let sb = &splitbelow
693- let &splitbelow = 0
694- exe win_id2win (a: w ).' close!'
695- let &splitbelow = sb
696- if j == -1
697- return
698- endif
699- let d = i - j
700- for i in d < 0 ? range (d + 1 , -1 ) : reverse (range (d ))
701- call win_move_statusline (winnr () + i , d < 0 ? - h : h )
702- endfor
703- endfunc
704-
705688function s: RestWinVars (w , vars)
706689 let vars = getwinvar (a: w , ' &' )
707690 for v in keys (a: vars )
@@ -738,7 +721,7 @@ function s:MoveWin(w, other, below)
738721 let nw = win_getid ()
739722 noa exe win_id2win (p != a: w ? p : nw).' wincmd w'
740723 noa exe win_id2win (w != a: w ? w : nw).' wincmd w'
741- noa call s: CloseWin (a: w )
724+ noa exe win_id2win (a: w ). ' close! '
742725 call s: RestWinVars (nw, vars)
743726 endif
744727endfunc
@@ -753,7 +736,7 @@ function s:NewCol(w)
753736 endif
754737 noa exe win_id2win (p ).' wincmd w'
755738 noa exe win_id2win (w ).' wincmd w'
756- call s: CloseWin (a: w )
739+ noa exe win_id2win (a: w ). ' close! '
757740endfunc
758741
759742function s: Scroll (topline)
@@ -856,7 +839,7 @@ function s:MiddleRelease(click)
856839 \ p .winrow <= winheight (p .winid)
857840 " off the statusline
858841 elseif p .wincol < 3
859- call s: CloseWin (p .winid)
842+ exe win_id2win (p .winid). ' close! '
860843 endif
861844 return
862845 endif
@@ -1171,6 +1154,36 @@ function s:BufWinLeave()
11711154 endif
11721155endfunc
11731156
1157+ function s: WinClosedPre ()
1158+ " Only works with 'nosplitbelow'
1159+ let w = str2nr (expand (" <amatch>" ))
1160+ let i = index (s: wins , w )
1161+ if i != -1
1162+ call remove (s: wins , i )
1163+ endif
1164+ let h = winheight (w ) + 1
1165+ let col = s: WinCol (w )
1166+ let [i , j ] = [index (col , w ), index (col , win_getid ())]
1167+ if j == -1 || j == i
1168+ let stack = filter (copy (s: wins ), {_, w - > index (col , w ) != -1 })
1169+ if stack == []
1170+ return
1171+ endif
1172+ if j == i
1173+ exe win_id2win (stack[-1 ]).' wincmd w'
1174+ endif
1175+ let j = index (col , stack[-1 ])
1176+ endif
1177+ call timer_start (0 , {_ - > s: WinClosedPost (col [j ], i - j , h )})
1178+ endfunc
1179+
1180+ function s: WinClosedPost (w , n , h )
1181+ let w = win_id2win (a: w )
1182+ for i in a: n < 0 ? range (a: n + 1 , -1 ) : reverse (range (a: n ))
1183+ call win_move_statusline (w + i , a: n < 0 ? - a: h : a: h )
1184+ endfor
1185+ endfunc
1186+
11741187augroup acme_vim
11751188au !
11761189au BufEnter * call s: ListDir ()
@@ -1180,6 +1193,8 @@ au TextChanged,TextChangedI guide setl nomodified
11801193au VimEnter * call s: ReloadDirs (winnr ())
11811194au VimResized * call s: ReloadDirs (0 )
11821195au WinResized * call s: ReloadDirs (0 )
1196+ au WinClosed * call s: WinClosedPre ()
1197+ au WinNew * call add (s: wins , win_getid ())
11831198augroup END
11841199
11851200if exists (" s:ctrlexe" )
@@ -1200,6 +1215,7 @@ let s:editcids = {}
12001215let s: editcmds = {}
12011216let s: jobs = []
12021217let s: scratch = {}
1218+ let s: wins = []
12031219
12041220if s: ctrlexe != ' '
12051221 let s: ctrl = job_start ([s: ctrlexe ], {
0 commit comments