0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

Fix some duplicates in ":find" completion. (Nazri Ramliy)

This commit is contained in:
Bram Moolenaar 2010-07-20 18:10:15 +02:00
parent 49771f4fb0
commit cb9d45cb84
2 changed files with 35 additions and 21 deletions

View File

@ -32,8 +32,6 @@ be worked on, but only if you sponsor Vim development. See |sponsor|.
GTK: torn-off menu doesn't work. GTK: torn-off menu doesn't work.
:find completion has duplicates. (Bjorn Winckler, 2010 Jul 18)
Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6) Cursor positioning wrong with 0x200e character. (John Becket, 2010 May 6)
Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb

View File

@ -9236,6 +9236,7 @@ unix_expandpath(gap, path, wildoff, flags, didstar)
#if defined(FEAT_SEARCHPATH) #if defined(FEAT_SEARCHPATH)
static int find_previous_pathsep __ARGS((char_u *path, char_u **psep)); static int find_previous_pathsep __ARGS((char_u *path, char_u **psep));
static int is_unique __ARGS((char_u *maybe_unique, garray_T *gap, int i)); static int is_unique __ARGS((char_u *maybe_unique, garray_T *gap, int i));
static void remove_duplicates __ARGS((garray_T *gap));
static void uniquefy_paths __ARGS((garray_T *gap, char_u *pattern)); static void uniquefy_paths __ARGS((garray_T *gap, char_u *pattern));
static int expand_in_path __ARGS((garray_T *gap, char_u *pattern, int flags)); static int expand_in_path __ARGS((garray_T *gap, char_u *pattern, int flags));
@ -9304,6 +9305,29 @@ is_unique(maybe_unique, gap, i)
return TRUE; return TRUE;
} }
/*
* Remove adjecent duplicate entries from "gap", which is a list of file names
* in allocated memory.
*/
static void
remove_duplicates(gap)
garray_T *gap;
{
int i;
int j;
char_u **fnames = (char_u **)gap->ga_data;
for (i = 1; i < gap->ga_len; ++i)
if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
{
vim_free(fnames[i]);
for (j = i + 1; j < gap->ga_len; ++j)
fnames[j - 1] = fnames[j];
--gap->ga_len;
--i;
}
}
/* /*
* Sorts, removes duplicates and modifies all the fullpath names in gap so that * Sorts, removes duplicates and modifies all the fullpath names in gap so that
* they are unique with respect to each other while conserving the part that * they are unique with respect to each other while conserving the part that
@ -9315,28 +9339,17 @@ uniquefy_paths(gap, pattern)
char_u *pattern; char_u *pattern;
{ {
int i; int i;
int j;
int len; int len;
char_u *pathsep_p; char_u *pathsep_p;
char_u *path; char_u *path;
char_u **fnames = (char_u **) gap->ga_data; char_u **fnames = (char_u **) gap->ga_data;
int sort_again = 0; int sort_again = 0;
char_u *pat; char_u *pat;
char_u *file_pattern; char_u *file_pattern;
regmatch_T regmatch; regmatch_T regmatch;
/* Remove duplicate entries */
sort_strings(fnames, gap->ga_len); sort_strings(fnames, gap->ga_len);
for (i = 0; i < gap->ga_len - 1; i++) remove_duplicates(gap);
if (fnamecmp(fnames[i], fnames[i+1]) == 0)
{
vim_free(fnames[i]);
for (j = i+1; j < gap->ga_len; j++)
fnames[j-1] = fnames[j];
gap->ga_len--;
i--;
}
/* /*
* We need to prepend a '*' at the beginning of file_pattern so that the * We need to prepend a '*' at the beginning of file_pattern so that the
@ -9379,7 +9392,10 @@ uniquefy_paths(gap, pattern)
} }
if (sort_again) if (sort_again)
{
sort_strings(fnames, gap->ga_len); sort_strings(fnames, gap->ga_len);
remove_duplicates(gap);
}
} }
/* /*