From 3a54ce5a73c78d9f45aa12a95cea4ee25f41e298 Mon Sep 17 00:00:00 2001 From: Harm te Hennepe Date: Wed, 12 Oct 2016 23:01:11 +0200 Subject: vim-patch:7.4.2274 (#5439) Problem: Command line completion on "find **/filename" drops sub-directory. Solution: Handle this case separately. (Harm te Hennepe, closes vim/vim#932, closes vim/vim#939) https://github.com/vim/vim/commit/73d4e4c8922f6f4d256f910a18f47c0c3a48c28b --- src/nvim/path.c | 33 +++++++++++++++++++++++---------- src/nvim/testdir/test_cmdline.vim | 8 ++++++++ src/nvim/version.c | 2 +- 3 files changed, 32 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index a79b7139f1..6149e1ab99 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -903,17 +903,30 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) /* Shorten the filename while maintaining its uniqueness */ path_cutoff = get_path_cutoff(path, &path_ga); - /* we start at the end of the path */ - pathsep_p = path + len - 1; - - while (find_previous_pathsep(path, &pathsep_p)) - if (vim_regexec(®match, pathsep_p + 1, (colnr_T)0) - && is_unique(pathsep_p + 1, gap, i) - && path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) { - sort_again = true; - memmove(path, pathsep_p + 1, STRLEN(pathsep_p)); - break; + // Don't assume all files can be reached without path when search + // pattern starts with **/, so only remove path_cutoff + // when possible. + if (pattern[0] == '*' && pattern[1] == '*' + && vim_ispathsep_nocolon(pattern[2]) + && path_cutoff != NULL + && vim_regexec(®match, path_cutoff, (colnr_T)0) + && is_unique(path_cutoff, gap, i)) { + sort_again = true; + memmove(path, path_cutoff, STRLEN(path_cutoff) + 1); + } else { + // Here all files can be reached without path, so get shortest + // unique path. We start at the end of the path. */ + pathsep_p = path + len - 1; + while (find_previous_pathsep(path, &pathsep_p)) { + if (vim_regexec(®match, pathsep_p + 1, (colnr_T)0) + && is_unique(pathsep_p + 1, gap, i) + && path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) { + sort_again = true; + memmove(path, pathsep_p + 1, STRLEN(pathsep_p)); + break; + } } + } if (path_is_absolute_path(path)) { /* diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 902ec1c05d..006f6b82a8 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -152,3 +152,11 @@ func Test_getcompletion() call assert_fails('call getcompletion("", "burp")', 'E475:') endfunc + +func Test_expand_star_star() + call mkdir('a/b', 'p') + call writefile(['asdfasdf'], 'a/b/fileXname') + call feedkeys(":find **/fileXname\\", 'xt') + call assert_equal('find a/b/fileXname', getreg(':')) + call delete('a', 'rf') +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index f2f81b5614..e6ad679f45 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -167,7 +167,7 @@ static int included_patches[] = { // 2277, // 2276, // 2275, - // 2274, + 2274, // 2273, // 2272, // 2271 NA -- cgit