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

Allow relaunching the providers pane from anywhere #328

Merged
merged 10 commits into from
Feb 27, 2020
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG
### Added

- Add new option `g:clap_insert_mode_only` to disable the feature of other mode, use the insert mode only. ([#335](https://github.com/liuchengxu/vim-clap/pull/335))
- Add new option `g:clap_providers_relaunch_code`(`@@` default). You can input `@@` or use <kbd>C-L</kbd> to invoke `:Clap` to reselect another provider at any time.([#328](https://github.com/liuchengxu/vim-clap/pull/328))
- Add new keymapping <kbd>C-L</kbd>.([#328](https://github.com/liuchengxu/vim-clap/pull/328))
- Now you can use `:Clap grep ++query=@visual` to search the visual selection. ([#336](https://github.com/liuchengxu/vim-clap/pull/336))

## [0.8] 2020-02-21
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Vim-clap is a modern generic interactive finder and dispatcher, based on the new
* [Commands](#commands)
* [Global variables](#global-variables)
* [Keybindings](#keybindings)
* [Insert mode](#insert-mode)
* [Normal mode](#normal-mode)
* [Execute some code during the process](#execute-some-code-during-the-process)
* [Change highlights](#change-highlights)
* [How to define your own provider](#how-to-define-your-own-provider)
Expand Down Expand Up @@ -192,13 +194,15 @@ See `:help clap-options` for more information.
- Use <kbd>Tab</kbd> to expand the directory for `:Clap filer`.
- [x] Use <kbd>Ctrl-t</kbd> or <kbd>Ctrl-x</kbd>, <kbd>Ctrl-v</kbd> to open the selected entry in a new tab or a new split.
- [x] Use <kbd>Ctrl-u</kbd> to clear inputs.
- [x] Use <kbd>Ctrl-l</kbd> to launch the whole provider list panel for invoking another provider at any time.

#### Normal mode

Normal mode mappings are neovim only now.

- [x] Use <kbd>j</kbd>/<kbd>Down</kbd> or <kbd>k</kbd>/<kbd>Up</kbd> to navigate the result list up and down linewise.
- [x] Use <kbd>Ctrl-d</kbd>/<kbd>Ctrl-u</kbd>/<kbd>PageDown</kbd>/<kbd>PageUp</kbd> to scroll the result list down and up.
- [x] Use <kbd>Ctrl-l</kbd> to launch the whole provider list panel for invoking another provider at any time.
- [x] Use <kbd>gg</kbd> and <kbd>G</kbd> to scroll to the first and last item.
- [x] Use <kbd>Enter</kbd> to select the entry and exit.
- [x] Actions defined by `g:clap_open_action`.
Expand Down
1 change: 1 addition & 0 deletions autoload/clap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ let g:clap_open_action = get(g:, 'clap_open_action', s:default_action)
let g:clap_enable_icon = get(g:, 'clap_enable_icon', exists('g:loaded_webdevicons') || get(g:, 'spacevim_nerd_fonts', 0))

let g:clap_insert_mode_only = get(g:, 'clap_insert_mode_only', v:false)
let g:clap_providers_relaunch_code = get(g:, 'clap_providers_relaunch_code', '@@')

function! s:inject_default_impl_is_ok(provider_info) abort
let provider_info = a:provider_info
Expand Down
9 changes: 9 additions & 0 deletions autoload/clap/floating_win.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ let s:preview_winhl = 'Normal:ClapPreview,EndOfBuffer:ClapPreviewInvisibleEndOfB
" | preview |
" -----------------------------
function! g:clap#floating_win#display.open() abort
if exists('s:display_winid') && nvim_win_is_valid(s:display_winid)
return
endif
" Check if the buffer is still valid as when switching between the sessions, it could become invalid.
if !nvim_buf_is_valid(s:display_bufnr)
let s:display_bufnr = nvim_create_buf(v:false, v:true)
Expand Down Expand Up @@ -122,6 +125,9 @@ function! s:open_win_border_left() abort
endfunction

function! g:clap#floating_win#spinner.open() abort
if exists('s:spinner_winid') && nvim_win_is_valid(s:spinner_winid)
return
endif
let opts = nvim_win_get_config(s:display_winid)
let opts.col += s:symbol_width
let opts.row -= 1
Expand Down Expand Up @@ -163,6 +169,9 @@ function! g:clap#floating_win#spinner.shrink() abort
endfunction

function! g:clap#floating_win#input.open() abort
if exists('s:input_winid') && nvim_win_is_valid(s:input_winid)
return
endif
let opts = nvim_win_get_config(s:spinner_winid)
let opts.col += opts.width
let opts.width = s:display_opts.width - opts.width - s:symbol_width * 2 - g:__clap_indicator_winwidth
Expand Down
19 changes: 19 additions & 0 deletions autoload/clap/handler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,30 @@ let s:old_input = ''
let s:multi_select_enabled = v:false
let s:support_multi_select = v:false

function! clap#handler#relaunch_providers() abort
call clap#handler#exit()
call timer_start(10, { -> clap#for('providers') })
call g:clap.input.set('')
endfunction

function! clap#handler#relaunch_is_ok() abort
if g:clap.input.get() ==# g:clap_providers_relaunch_code
call clap#handler#relaunch_providers()
return v:true
endif
return v:false
endfunction

function! clap#handler#on_typed() abort
if clap#handler#relaunch_is_ok()
return
endif

if g:clap.provider.is_rpc_type()
call g:clap.provider.on_typed()
return
endif

let l:cur_input = g:clap.input.get()
if s:old_input == l:cur_input
return
Expand Down
8 changes: 8 additions & 0 deletions autoload/clap/popup/move_manager.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function! s:move_manager.ctrl_e(_winid) abort
call s:mock_input()
endfunction

function! s:move_manager.ctrl_l(_winid) abort
call clap#handler#relaunch_providers()
endfunction

function! s:apply_on_typed() abort
if g:clap.provider.is_sync()
let g:__clap_should_refilter = v:true
Expand Down Expand Up @@ -121,6 +125,7 @@ let s:move_manager["\<C-H>"] = s:move_manager.bs
let s:move_manager["\<C-D>"] = s:move_manager.ctrl_d
let s:move_manager["\<C-G>"] = s:move_manager["\<Esc>"]
let s:move_manager["\<C-U>"] = s:move_manager.ctrl_u
let s:move_manager["\<C-L>"] = s:move_manager.ctrl_l

function! s:define_open_action_filter() abort
for k in keys(g:clap_open_action)
Expand Down Expand Up @@ -167,6 +172,9 @@ function! s:apply_input(_timer) abort
endfunction

function! s:apply_input_with_delay() abort
if clap#handler#relaunch_is_ok()
return
endif
if s:input_timer != -1
call timer_stop(s:input_timer)
endif
Expand Down
12 changes: 12 additions & 0 deletions doc/clap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ g:clap_insert_mode_only *g:clap_insert_mode_only*
to `v:true` .


g:clap_providers_relaunch_code *g:clap_providers_relaunch_code*

Type: |String|
Default: `'@@'`

This feature is inspired by VS code command palette prefix-based searching.
You can input `@@` or use `<C-L>` to invoke `:Clap` to reselect the provider
at any time. Although it does not use the prefix searching, it's more
convient due to the inherent fuzzy matching feature of vim-clap since you
don't have to remember each provider's prefix.


g:clap_disable_run_rooter *g:clap_disable_run_rooter*

Type: |Bool|
Expand Down
4 changes: 4 additions & 0 deletions ftplugin/clap_input.vim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ endif

inoremap <silent> <buffer> <expr> <C-E> col('.')>strlen(getline('.'))<bar><bar>pumvisible()?"\<Lt>C-E>":"\<Lt>End>"

inoremap <silent> <buffer> <C-l> <Esc>:call clap#handler#relaunch_providers()<CR>

inoremap <silent> <buffer> <CR> <Esc>:<c-u>call clap#handler#sink()<CR>
inoremap <silent> <buffer> <C-c> <Esc>:<c-u>call clap#handler#exit()<CR>
inoremap <silent> <buffer> <C-g> <Esc>:<c-u>call clap#handler#exit()<CR>
Expand Down Expand Up @@ -71,6 +73,8 @@ nnoremap <silent> <buffer> <CR> :<c-u>call clap#handler#sink()<CR>
nnoremap <silent> <buffer> <C-c> :<c-u>call clap#handler#exit()<CR>
nnoremap <silent> <buffer> <C-g> :<c-u>call clap#handler#exit()<CR>

nnoremap <silent> <buffer> <C-l> :<c-u>call clap#handler#relaunch_providers()<CR>

nnoremap <silent> <buffer> <Down> :<c-u>call clap#navigation#linewise('down')<CR>
nnoremap <silent> <buffer> <Up> :<c-u>call clap#navigation#linewise('up')<CR>

Expand Down