Repository navigation
Expand file tree
/
Copy pathlist.vim
More file actions
59 lines (48 loc) · 1.59 KB
/
Copy pathlist.vim
File metadata and controls
59 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function! phpactor#input#list#inputlist(label, choices, multi, ResultHandler)
echo a:label
let choice = inputlist(s:add_number_to_choices(a:choices))
if (choice == 0)
throw "cancelled"
endif
call a:ResultHandler(a:choices[choice - 1])
endfunction
" expreimental: this stategy currently does not work when used in a
" non-terminal RPC step - https://github.com/phpactor/phpactor/issues/845
function! phpactor#input#list#fzf(label, choices, multi, ResultHandler)
let options = [
\ '--tiebreak=index',
\ '--layout=reverse-list',
\ ]
let sink = {
\ 'sink': {key -> a:ResultHandler(a:choices[key - 1])},
\ }
if a:multi
call extend(options, [
\ '--multi',
\ '--bind=ctrl-a:select-all,ctrl-d:deselect-all',
\ ])
let sink = {
\ 'sink*': {results -> a:ResultHandler(map(
\ results,
\ {key, value -> a:choices[value - 1]}
\ ))}
\ }
endif
" sink works because "key" is converted to integer, so only the number is kept
call fzf#run(extend({
\ 'source': s:add_number_to_choices(a:choices),
\ 'down': '30%',
\ 'options': options
\ }, sink))
endfunction
function! s:auto_detect_strategy()
let strategy = 'inputlist'
if get(g:, 'loaded_fzf', 0)
let strategy = 'fzf'
endif
return 'phpactor#input#list#'. strategy
endfunction
function! s:add_number_to_choices(choices)
return map(copy(a:choices), {key, value -> key + 1 .') '. value})
endfunction
" vim: et ts=4 sw=4 fdm=marker