@@ -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,34 @@ function s:BufWinLeave()
11711154 endif
11721155endfunc
11731156
1157+ function s: WinClosedPre ()
1158+ " Only works with 'nosplitbelow'
1159+ let w = expand (" <amatch>" )
1160+ let h = winheight (w ) + 1
1161+ let col = s: WinCol (w )
1162+ let [i , j ] = [index (col , w ), index (col , win_getid ())]
1163+ if j == -1
1164+ let fbelow = i + 1 == len (col ) ? ' ' :
1165+ \ fnamemodify (bufname (winbufnr (col [i + 1 ])), ' :t' )
1166+ if i == 0 || fbelow != ' guide'
1167+ return
1168+ endif
1169+ let j = i - 1
1170+ endif
1171+ let focus = w == win_getid ()
1172+ call timer_start (0 , {_ - > s: WinClosedPost (col [j ], i - j , h , focus)})
1173+ endfunc
1174+
1175+ function s: WinClosedPost (w , n , h , focus)
1176+ let w = win_id2win (a: w )
1177+ for i in a: n < 0 ? range (a: n + 1 , -1 ) : reverse (range (a: n ))
1178+ call win_move_statusline (w + i , a: n < 0 ? - a: h : a: h )
1179+ endfor
1180+ if a: focus
1181+ exe w .' wincmd w'
1182+ endif
1183+ endfunc
1184+
11741185augroup acme_vim
11751186au !
11761187au BufEnter * call s: ListDir ()
@@ -1180,6 +1191,7 @@ au TextChanged,TextChangedI guide setl nomodified
11801191au VimEnter * call s: ReloadDirs (winnr ())
11811192au VimResized * call s: ReloadDirs (0 )
11821193au WinResized * call s: ReloadDirs (0 )
1194+ au WinClosed * call s: WinClosedPre ()
11831195augroup END
11841196
11851197if exists (" s:ctrlexe" )
0 commit comments