mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-02-07 18:31:08 +08:00
Fix #134 - ":e CURRENT_FILE" can cause error when modified
This commit is contained in:
@@ -106,6 +106,13 @@ let s:default_action = {
|
|||||||
\ 'ctrl-x': 'split',
|
\ 'ctrl-x': 'split',
|
||||||
\ 'ctrl-v': 'vsplit' }
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
|
function! s:open(cmd, target)
|
||||||
|
if stridx('edit', a:cmd) == 0 && fnamemodify(a:target, ':p') ==# expand('%:p')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
execute a:cmd s:escape(a:target)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:common_sink(lines) abort
|
function! s:common_sink(lines) abort
|
||||||
if len(a:lines) < 2
|
if len(a:lines) < 2
|
||||||
return
|
return
|
||||||
@@ -127,7 +134,7 @@ function! s:common_sink(lines) abort
|
|||||||
execute 'e' s:escape(item)
|
execute 'e' s:escape(item)
|
||||||
let empty = 0
|
let empty = 0
|
||||||
else
|
else
|
||||||
execute cmd s:escape(item)
|
call s:open(cmd, item)
|
||||||
endif
|
endif
|
||||||
if exists('#BufEnter') && isdirectory(item)
|
if exists('#BufEnter') && isdirectory(item)
|
||||||
doautocmd BufEnter
|
doautocmd BufEnter
|
||||||
@@ -201,7 +208,7 @@ function! s:line_handler(lines)
|
|||||||
endif
|
endif
|
||||||
normal! m'
|
normal! m'
|
||||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
||||||
if !empty(cmd)
|
if !empty(cmd) && stridx('edit', cmd) < 0
|
||||||
execute 'silent' cmd
|
execute 'silent' cmd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -474,7 +481,7 @@ function! s:ag_handler(lines)
|
|||||||
|
|
||||||
let first = list[0]
|
let first = list[0]
|
||||||
try
|
try
|
||||||
execute cmd s:escape(first.filename)
|
call s:open(cmd, first.filename)
|
||||||
execute first.lnum
|
execute first.lnum
|
||||||
execute 'normal!' first.col.'|zz'
|
execute 'normal!' first.col.'|zz'
|
||||||
catch
|
catch
|
||||||
@@ -580,7 +587,7 @@ function! s:tags_sink(lines)
|
|||||||
for line in a:lines[1:]
|
for line in a:lines[1:]
|
||||||
let parts = split(line, '\t\zs')
|
let parts = split(line, '\t\zs')
|
||||||
let excmd = matchstr(join(parts[2:], ''), '^.*\ze;"\t')
|
let excmd = matchstr(join(parts[2:], ''), '^.*\ze;"\t')
|
||||||
execute cmd s:escape(parts[1][:-2])
|
call s:open(cmd, parts[1][:-2])
|
||||||
execute excmd
|
execute excmd
|
||||||
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
|
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
|
||||||
endfor
|
endfor
|
||||||
|
|||||||
Reference in New Issue
Block a user