From a3a340a9e9e1856a46c079186354f163cfc5febc Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 7 Mar 2015 16:53:02 +0100 Subject: fixed TAB completion of files in the current directory beginning with "." We used g_path_get_dirname() which does not always return strict prefixes of the input file name. For file names without directory, it returns "." (the current directory). This is useful for passing that directory to functions expecting a proper directory (like g_dir_open()) but was unsuitable for building file name candidates for autocompletion. Therefore, we tried to determine if the dirname is a prefix of the filename. This however failed for "hidden" file names beginning with dot. All in all it is easier to calculate our own directory name based on the previously calculated basename than to handle the current-directory case with g_path_get_dirname(). Now we'll get "" for the current directory, so we have to handle the empty-string-is-current-dir case. --- src/cmdline.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/cmdline.cpp') diff --git a/src/cmdline.cpp b/src/cmdline.cpp index 4a04277..b4c7b18 100644 --- a/src/cmdline.cpp +++ b/src/cmdline.cpp @@ -556,20 +556,25 @@ filename_complete(const gchar *filename, gchar completed) dir_sep[0] = derive_dir_separator(filename); dir_sep[1] = '\0'; - dirname = g_path_get_dirname(filename); - dir = g_dir_open(dirname, 0, NULL); - if (!dir) { - g_free(dirname); - return NULL; - } - if (*dirname != *filename) - *dirname = '\0'; - + /* + * Derive base and directory names. + * We do not use g_path_get_basename() or g_path_get_dirname() + * since we need strict suffixes and prefixes of filename + * in order to construct paths of entries in dirname + * that are suitable for auto completion. + */ basename = strrchr(filename, *dir_sep); if (basename) basename++; else basename = filename; + dirname = g_strndup(filename, basename-filename); + + dir = g_dir_open(*dirname ? dirname : ".", 0, NULL); + if (!dir) { + g_free(dirname); + return NULL; + } while ((cur_basename = g_dir_read_name(dir))) { gchar *cur_filename = g_build_path(dir_sep, dirname, cur_basename, NIL); -- cgit v1.2.3