From a76611b448fb1e0d4d21831ea8490311045e4142 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 15 Apr 2022 19:32:42 +0800 Subject: [PATCH] fix(denite): fix denite_next/prev function --- config/plugins/denite.vim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/config/plugins/denite.vim b/config/plugins/denite.vim index c06a996c5..d85e379be 100644 --- a/config/plugins/denite.vim +++ b/config/plugins/denite.vim @@ -186,7 +186,10 @@ function! s:denite_filter_my_settings() abort call s:clear_imap('%') imap (denite_filter_quit) imap (denite_filter_quit):q - if exists('*nvim_win_get_cursor') && exists('*nvim_win_set_cursor') + if exists('*nvim_win_get_cursor') + \ && exists('*nvim_win_set_cursor') + \ && exists('*nvim_buf_line_count') + \ && exists('*nvim_win_get_buf') inoremap denite_next() inoremap denite_prev() inoremap denite_next() @@ -212,13 +215,23 @@ endfunction function! s:denite_next() abort let win_cursor = nvim_win_get_cursor(s:denite_winid) - call nvim_win_set_cursor(s:denite_winid, [win_cursor[0] + 1, win_cursor[1]]) + let line = nvim_buf_line_count(nvim_win_get_buf(s:denite_winid)) + if win_cursor[0] < line + call nvim_win_set_cursor(s:denite_winid, [win_cursor[0] + 1, win_cursor[1]]) + else + call nvim_win_set_cursor(s:denite_winid, [1, win_cursor[1]]) + endif return '' endfunction function! s:denite_prev() abort let win_cursor = nvim_win_get_cursor(s:denite_winid) - call nvim_win_set_cursor(s:denite_winid, [win_cursor[0] - 1, win_cursor[1]]) + if win_cursor[0] > 1 + call nvim_win_set_cursor(s:denite_winid, [win_cursor[0] - 1, win_cursor[1]]) + else + let line = nvim_buf_line_count(nvim_win_get_buf(s:denite_winid)) + call nvim_win_set_cursor(s:denite_winid, [line, win_cursor[1]]) + endif return '' endfunction