Skip to content

Commit 6bad3f4

Browse files
committed
Manage WinLeave/WinEnter events
1 parent 65cde0b commit 6bad3f4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

autoload/vital/_easymotion/HitAHint/Motion.vim

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,24 @@ function! s:overwin.pattern(pattern) abort
8080
let winpos = self.select_winpos(self.gather_poses_overwin(a:pattern), self.config.keys)
8181
if winpos is# -1
8282
else
83-
let [winnr_str, pos] = winpos
84-
let winnr = str2nr(winnr_str)
85-
if winnr is# winnr()
86-
normal! m`
87-
else
88-
call s:move_to_win(winnr)
89-
endif
90-
call cursor(pos)
83+
call s:move_to_winpos(winpos)
84+
endif
85+
endfunction
86+
87+
" @param {{winnr: [lnum, cnum]}}
88+
function! s:move_to_winpos(winpos) abort
89+
let [winnr_str, pos] = a:winpos
90+
let winnr = str2nr(winnr_str)
91+
let is_win_moved = !(winnr is# winnr())
92+
if is_win_moved
93+
doautocmd WinLeave *
94+
call s:move_to_win(winnr)
95+
else
96+
normal! m`
97+
endif
98+
call cursor(pos)
99+
if is_win_moved
100+
doautocmd WinEnter *
91101
endif
92102
endfunction
93103

@@ -560,7 +570,7 @@ endfunction
560570
" @param {number} winnr
561571
function! s:move_to_win(winnr) abort
562572
if a:winnr !=# winnr()
563-
execute a:winnr . 'wincmd w'
573+
execute 'noautocmd' a:winnr . 'wincmd w'
564574
endif
565575
endfunction
566576

0 commit comments

Comments
 (0)