Skip to content

Commit 09e1774

Browse files
committed
fix path input error for multi paths in one line
1 parent ba5374a commit 09e1774

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

autoload/easycomplete/sources/path.vim

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let s:util_toolkit = has('nvim') ? v:lua.require("easycomplete.util") : v:null
12

23
function! easycomplete#sources#path#completor(opt, ctx)
34
let l:typing_path = s:TypingAPath(a:ctx)
@@ -141,6 +142,21 @@ function! easycomplete#sources#path#TypingAPath(...)
141142
return call(function('s:TypingAPath'), a:000)
142143
endfunction
143144

145+
function! s:GetFullPath(prefx)
146+
if g:env_is_nvim
147+
let fpath = s:util_toolkit.get_fullpath(a:prefx)
148+
else
149+
try
150+
let fpath = matchstr(a:prefx,"\\([\\(\\) \"'\\t\\[\\]\\{\\}]\\)\\@<=" .
151+
\ "\\([\\/\\.\\~]\\+[\\.\\/a-zA-Z0-9\u2e80-\uef4f\\_\\- ]\\+\\|[\\.\\/]\\)")
152+
catch /^Vim\%((\a\+)\)\=:E945/
153+
let fpath = matchstr(a:prefx,"\\([\\(\\) \"'\\t\\[\\]\\{\\}]\\)\\@<=" .
154+
\ "\\([\\/\\.\\~]\\+[\\.\\/a-zA-Z0-9\\_\\- ]\\+\\|[\\.\\/]\\)")
155+
endtry
156+
endif
157+
return fpath
158+
endfunction
159+
144160
" 判断当前是否正在输入一个地址path
145161
" base 原本想传入当前文件名字,实际上传不进来,这里也没用到
146162
" s:TypingAPath(ctx) 参数是ctx时,在当前脚本中调用
@@ -166,14 +182,7 @@ function! s:TypingAPath(...)
166182
" \<Tab> => done
167183
" xxxss \ xxxss<Tab> => done
168184
" MoreInfo: #140
169-
try
170-
let fpath = matchstr(prefx,"\\([\\(\\) \"'\\t\\[\\]\\{\\}]\\)\\@<=" .
171-
\ "\\([\\/\\.\\~]\\+[\\.\\/a-zA-Z0-9\u2e80-\uef4f\\_\\- ]\\+\\|[\\.\\/]\\)")
172-
catch /^Vim\%((\a\+)\)\=:E945/
173-
let fpath = matchstr(prefx,"\\([\\(\\) \"'\\t\\[\\]\\{\\}]\\)\\@<=" .
174-
\ "\\([\\/\\.\\~]\\+[\\.\\/a-zA-Z0-9\\_\\- ]\\+\\|[\\.\\/]\\)")
175-
endtry
176-
185+
let fpath = s:GetFullPath(prefx)
177186
" 兼容单个 '/' 匹配的情况
178187
let spath = s:GetPathName(substitute(fpath,"^[\\.\\/].*\\/","./","g"))
179188
" 清除对 '\' 的路径识别

lua/easycomplete/util.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ function util.zizzing()
6767
end
6868
end
6969

70+
function util.get_fullpath(prefx)
71+
local last_path
72+
-- 匹配包含斜杠的路径(如 ./a/b/c、../a/b/c、/a/b/c 等)
73+
for path in string.gmatch(prefx, "%S+/[^%s]*") do
74+
last_path = path
75+
end
76+
return last_path or ""
77+
end
78+
7079
-- 求一个列表t的前limit个元素
7180
-- util.sub_table({...}, 1, 20) 求列表从1到20个元素
7281
function util.sub_table(t, from, to)

0 commit comments

Comments
 (0)