Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for <PageUp> and <PageDown> #232

Merged
merged 4 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<C-O>`.([#227](https://github.com/github.com/liuchengxu/vim-clap/pull/2277).
- Add `<PageDown>` and `<PageUp>` keybindings. ([#232](https://github.com/liuchengxu/vim-clap/pull/232))

### Improved

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ See `:help clap-options` for more information.

### Keybindings

- [x] Use <kbd>Ctrl-j</kbd>/<kbd>Down</kbd> or <kbd>Ctrl-k</kbd>/<kbd>Up</kbd> to navigate the result list up and down.
- [x] Use <kbd>Ctrl-j</kbd>/<kbd>Down</kbd> or <kbd>Ctrl-k</kbd>/<kbd>Up</kbd> to navigate the result list up and down linewise.
- [x] Use <kbd>PageDown</kbd>/<kbd>PageUp</kbd> to scroll the result list down and up.
- [x] Use <kbd>Ctrl-a</kbd>/<kbd>Home</kbd> to go to the start of the input.
- [x] Use <kbd>Ctrl-e</kbd>/<kbd>End</kbd> to go to the end of the input.
- [x] Use <kbd>Ctrl-c</kbd>, <kbd>Ctrl-g</kbd>, <kbd>Ctrl-[</kbd> or <kbd>Esc</kbd> to exit.
Expand Down
34 changes: 26 additions & 8 deletions autoload/clap/handler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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('$')
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/clap/popup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ let s:move_manager["\<C-J>"] = { winid -> win_execute(winid, 'noautocmd call cla
let s:move_manager["\<Down>"] = s:move_manager["\<C-J>"]
let s:move_manager["\<C-K>"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#navigate_result("up")') }
let s:move_manager["\<Up>"] = s:move_manager["\<C-K>"]
let s:move_manager["\<PageUp>"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#scroll("up")') }
let s:move_manager["\<PageDown>"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#scroll("down")') }
let s:move_manager["\<Tab>"] = { winid -> win_execute(winid, 'noautocmd call clap#handler#select_toggle()') }
let s:move_manager["\<CR>"] = { _winid -> clap#handler#sink() }
let s:move_manager["\<Esc>"] = { _winid -> clap#handler#exit() }
Expand Down
4 changes: 3 additions & 1 deletion doc/clap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions ftplugin/clap_input.vim
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ inoremap <silent> <buffer> <C-k> <C-R>=clap#handler#navigate_result('up')<CR>
inoremap <silent> <buffer> <Down> <C-R>=clap#handler#navigate_result('down')<CR>
inoremap <silent> <buffer> <Up> <C-R>=clap#handler#navigate_result('up')<CR>

inoremap <silent> <buffer> <PageDown> <C-R>=clap#handler#scroll('down')<CR>
inoremap <silent> <buffer> <PageUp> <C-R>=clap#handler#scroll('up')<CR>

inoremap <silent> <buffer> <Tab> <C-R>=clap#handler#select_toggle()<CR>

call clap#util#define_open_action_mappings()