Skip to content

Commit

Permalink
Add support for <PageUp> and <PageDown>
Browse files Browse the repository at this point in the history
Close #225
  • Loading branch information
liuchengxu committed Jan 13, 2020
1 parent 290d58f commit de536fb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
28 changes: 25 additions & 3 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 Down Expand Up @@ -100,19 +112,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 +150,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
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()

0 comments on commit de536fb

Please sign in to comment.