mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-23 04:21:27 +08:00
Ignore Funcref actions in g:fzf_action
A Funcref action in g:fzf_action only handles a list of file paths so
they can't be used to open windows.
Related:
- #185
- 2069bbc8b5
This commit is contained in:
@@ -185,6 +185,12 @@ let s:default_action = {
|
|||||||
\ 'ctrl-x': 'split',
|
\ 'ctrl-x': 'split',
|
||||||
\ 'ctrl-v': 'vsplit' }
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
|
function! s:action_for(key, ...)
|
||||||
|
let default = a:0 ? a:1 : ''
|
||||||
|
let Cmd = get(get(g:, 'fzf_action', s:default_action), a:key, default)
|
||||||
|
return type(Cmd) == s:TYPE.string ? Cmd : default
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:open(cmd, target)
|
function! s:open(cmd, target)
|
||||||
if stridx('edit', a:cmd) == 0 && fnamemodify(a:target, ':p') ==# expand('%:p')
|
if stridx('edit', a:cmd) == 0 && fnamemodify(a:target, ':p') ==# expand('%:p')
|
||||||
return
|
return
|
||||||
@@ -258,7 +264,7 @@ function! s:line_handler(lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
normal! m'
|
normal! m'
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = s:action_for(a:lines[0])
|
||||||
if !empty(cmd) && stridx('edit', cmd) < 0
|
if !empty(cmd) && stridx('edit', cmd) < 0
|
||||||
execute 'silent' cmd
|
execute 'silent' cmd
|
||||||
endif
|
endif
|
||||||
@@ -327,7 +333,7 @@ function! s:buffer_line_handler(lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
normal! m'
|
normal! m'
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = s:action_for(a:lines[0])
|
||||||
if !empty(cmd)
|
if !empty(cmd)
|
||||||
execute 'silent' cmd
|
execute 'silent' cmd
|
||||||
endif
|
endif
|
||||||
@@ -513,7 +519,7 @@ function! s:bufopen(lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = s:action_for(a:lines[0])
|
||||||
if !empty(cmd)
|
if !empty(cmd)
|
||||||
execute 'silent' cmd
|
execute 'silent' cmd
|
||||||
endif
|
endif
|
||||||
@@ -567,7 +573,7 @@ function! s:ag_handler(lines, with_column)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
|
let cmd = s:action_for(a:lines[0], 'e')
|
||||||
let list = map(filter(a:lines[1:], 'len(v:val)'), 's:ag_to_qf(v:val, a:with_column)')
|
let list = map(filter(a:lines[1:], 'len(v:val)'), 's:ag_to_qf(v:val, a:with_column)')
|
||||||
if empty(list)
|
if empty(list)
|
||||||
return
|
return
|
||||||
@@ -661,7 +667,7 @@ function! s:btags_sink(lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
normal! m'
|
normal! m'
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = s:action_for(a:lines[0])
|
||||||
if !empty(cmd)
|
if !empty(cmd)
|
||||||
execute 'silent' cmd '%'
|
execute 'silent' cmd '%'
|
||||||
endif
|
endif
|
||||||
@@ -711,7 +717,7 @@ function! s:tags_sink(lines)
|
|||||||
endif
|
endif
|
||||||
normal! m'
|
normal! m'
|
||||||
let qfl = []
|
let qfl = []
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
|
let cmd = s:action_for(a:lines[0], 'e')
|
||||||
try
|
try
|
||||||
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
|
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
|
||||||
for line in a:lines[1:]
|
for line in a:lines[1:]
|
||||||
@@ -880,7 +886,7 @@ function! s:mark_sink(lines)
|
|||||||
if len(a:lines) < 2
|
if len(a:lines) < 2
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = s:action_for(a:lines[0])
|
||||||
if !empty(cmd)
|
if !empty(cmd)
|
||||||
execute 'silent' cmd
|
execute 'silent' cmd
|
||||||
endif
|
endif
|
||||||
@@ -978,12 +984,13 @@ function! s:commits_sink(lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cmd = get(extend({'ctrl-d': ''}, get(g:, 'fzf_action', s:default_action)), a:lines[0], 'e')
|
let diff = a:lines[0] == 'ctrl-d'
|
||||||
|
let cmd = s:action_for(a:lines[0], 'e')
|
||||||
let buf = bufnr('')
|
let buf = bufnr('')
|
||||||
for idx in range(1, len(a:lines) - 1)
|
for idx in range(1, len(a:lines) - 1)
|
||||||
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}')
|
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}')
|
||||||
if !empty(sha)
|
if !empty(sha)
|
||||||
if empty(cmd)
|
if diff
|
||||||
if idx > 1
|
if idx > 1
|
||||||
execute 'tab sb' buf
|
execute 'tab sb' buf
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user