diff --git a/CHANGELOG.md b/CHANGELOG.md index 94041cb25..d3cc1a7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ CHANGELOG - Provide the prebuilt binary support since [Release v0.4](https://github.com/liuchengxu/vim-clap/releases/tag/v0.4). - Add script for downloading the prebuilt binary easily and support downloading via plugin manager directly.([#222](https://github.com/github.com/liuchengxu/vim-clap/pull/222)) - Push the current position to the jumplist for `blines` provider so that you can jump back using ``.([#227](https://github.com/github.com/liuchengxu/vim-clap/pull/2277). +- Add `` and `` keybindings. ([#232](https://github.com/liuchengxu/vim-clap/pull/232)) ### Improved diff --git a/README.md b/README.md index fedc7b9b4..dbf7152ad 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,8 @@ See `:help clap-options` for more information. ### Keybindings -- [x] Use Ctrl-j/Down or Ctrl-k/Up to navigate the result list up and down. +- [x] Use Ctrl-j/Down or Ctrl-k/Up to navigate the result list up and down linewise. +- [x] Use PageDown/PageUp to scroll the result list down and up. - [x] Use Ctrl-a/Home to go to the start of the input. - [x] Use Ctrl-e/End to go to the end of the input. - [x] Use Ctrl-c, Ctrl-g, Ctrl-[ or Esc to exit. diff --git a/autoload/clap/handler.vim b/autoload/clap/handler.vim index 392dfbf88..da5ede688 100644 --- a/autoload/clap/handler.vim +++ b/autoload/clap/handler.vim @@ -48,6 +48,18 @@ function! s:load_cache() abort call g:clap.display.append_lines_uncheck(to_append) endfunction +function! s:scroll(direction) abort + let scroll_lines = getwinvar(g:clap.display.winid, '&scroll') + if a:direction ==# 'down' + execute 'normal!' scroll_lines.'j' + else + execute 'normal!' scroll_lines.'k' + endif + + let g:__clap_display_curlnum = line('.') + call clap#sign#toggle_cursorline() +endfunction + function! s:navigate(direction) abort let curlnum = line('.') let lastlnum = line('$') @@ -61,33 +73,29 @@ function! s:navigate(direction) abort if !g:clap_disable_bottom_top normal! 1gg - let g:__clap_display_curlnum = 1 endif else call s:load_cache() normal! j - let g:__clap_display_curlnum += 1 endif elseif curlnum == 1 && a:direction ==# 'up' if !g:clap_disable_bottom_top normal! G - let g:__clap_display_curlnum = lastlnum endif else if a:direction ==# 'down' normal! j - let g:__clap_display_curlnum +=1 else normal! k - let g:__clap_display_curlnum -=1 endif endif + let g:__clap_display_curlnum = line('.') call clap#sign#toggle_cursorline() endfunction @@ -100,19 +108,26 @@ function! s:on_move_safe() abort endfunction if has('nvim') - function! clap#handler#navigate_result(direction) abort + function! s:wrap_insert_move(Move, args) abort call g:clap.display.goto_win() - call s:navigate(a:direction) + call call(a:Move, a:args) call g:clap.input.goto_win() - call s:on_move_safe() " Must return '' explicitly return '' endfunction + function! clap#handler#navigate_result(direction) abort + return s:wrap_insert_move(function('s:navigate'), [a:direction]) + endfunction + + function! clap#handler#scroll(direction) abort + return s:wrap_insert_move(function('s:scroll'), [a:direction]) + endfunction + function! clap#handler#internal_navigate(direction) abort call g:clap.display.goto_win() call s:navigate(a:direction) @@ -131,6 +146,9 @@ else call win_execute(g:clap.display.winid, 'call s:navigate(a:direction)') endfunction + function! clap#handler#scroll(direction) abort + call win_execute(g:clap.display.winid, 'call s:scroll(a:direction)') + endfunction endif function! clap#handler#sink() abort diff --git a/autoload/clap/popup.vim b/autoload/clap/popup.vim index 236bc4802..a27bbf338 100644 --- a/autoload/clap/popup.vim +++ b/autoload/clap/popup.vim @@ -428,6 +428,8 @@ let s:move_manager["\"] = { winid -> win_execute(winid, 'noautocmd call cla let s:move_manager["\"] = s:move_manager["\"] let s:move_manager["\"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#navigate_result("up")') } let s:move_manager["\"] = s:move_manager["\"] +let s:move_manager["\"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#scroll("up")') } +let s:move_manager["\"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#scroll("down")') } let s:move_manager["\"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#select_toggle()') } let s:move_manager["\"] = { _winid -> clap#handler#sink() } let s:move_manager["\"] = { _winid -> clap#handler#exit() } diff --git a/doc/clap.txt b/doc/clap.txt index 3d9e99e3c..5901f704d 100644 --- a/doc/clap.txt +++ b/doc/clap.txt @@ -877,7 +877,9 @@ The form of `[++opt]` is `++{optname}={value}`, where {optname} is one of: *clap-keybindings* -- Use `Ctrl-j`/`Down` or `Ctrl-k`/`Up` to navigate the result list up and down. +- Use `Ctrl-j`/`Down` or `Ctrl-k`/`Up` to navigate the result list up and down linewise. + +- Use `PageDown`/`PageUp` to scroll the result list down and up. - Use `Ctrl-a`/`Home` to go to the start of the input. diff --git a/ftplugin/clap_input.vim b/ftplugin/clap_input.vim index 079648446..46e0c7294 100644 --- a/ftplugin/clap_input.vim +++ b/ftplugin/clap_input.vim @@ -60,6 +60,9 @@ inoremap =clap#handler#navigate_result('up') inoremap =clap#handler#navigate_result('down') inoremap =clap#handler#navigate_result('up') +inoremap =clap#handler#scroll('down') +inoremap =clap#handler#scroll('up') + inoremap =clap#handler#select_toggle() call clap#util#define_open_action_mappings()