]> granicus.if.org Git - vim/commitdiff
Fix some duplicates in ":find" completion. (Nazri Ramliy)
authorBram Moolenaar <Bram@vim.org>
Tue, 20 Jul 2010 16:10:15 +0000 (18:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 20 Jul 2010 16:10:15 +0000 (18:10 +0200)
runtime/doc/todo.txt
src/misc1.c

index 1dabb75f052d7eee2df4992c2a7f831f3fc57907..a77f68490de0594489b4164a287057862d338c4d 100644 (file)
@@ -32,8 +32,6 @@ be worked on, but only if you sponsor Vim development.  See |sponsor|.
 
 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)
 
 Test 69 breaks on MS-Windows, both 32 and 64 builds. (George Reilly, 2010 Feb
index cd5ae4b2f66ab12ca926b935f1b9dc186e2e0a55..8e2c656e21116119fb51c53bf1ec540dde30a2a5 100644 (file)
@@ -9236,6 +9236,7 @@ unix_expandpath(gap, path, wildoff, flags, didstar)
 #if defined(FEAT_SEARCHPATH)
 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 void remove_duplicates __ARGS((garray_T *gap));
 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));
 
@@ -9305,38 +9306,50 @@ is_unique(maybe_unique, gap, i)
 }
 
 /*
- * 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
- * matches the pattern. Beware, this is at least O(n^2) wrt gap->ga_len.
+ * Remove adjecent duplicate entries from "gap", which is a list of file names
+ * in allocated memory.
  */
     static void
-uniquefy_paths(gap, pattern)
+remove_duplicates(gap)
     garray_T *gap;
-    char_u *pattern;
 {
     int            i;
     int            j;
-    int            len;
-    char_u  *pathsep_p;
-    char_u  *path;
-    char_u  **fnames = (char_u **) gap->ga_data;
+    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
+ * they are unique with respect to each other while conserving the part that
+ * matches the pattern. Beware, this is at least O(n^2) wrt gap->ga_len.
+ */
+    static void
+uniquefy_paths(gap, pattern)
+    garray_T   *gap;
+    char_u     *pattern;
+{
+    int                i;
+    int                len;
+    char_u     *pathsep_p;
+    char_u     *path;
+    char_u     **fnames = (char_u **) gap->ga_data;
     int                sort_again = 0;
     char_u     *pat;
     char_u      *file_pattern;
     regmatch_T regmatch;
 
-    /* Remove duplicate entries */
     sort_strings(fnames, gap->ga_len);
-    for (i = 0; i < gap->ga_len - 1; i++)
-       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--;
-       }
+    remove_duplicates(gap);
 
     /*
      * 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)
+    {
        sort_strings(fnames, gap->ga_len);
+       remove_duplicates(gap);
+    }
 }
 
 /*