diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-03-07 16:53:02 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-03-07 16:53:02 +0100 |
commit | a3a340a9e9e1856a46c079186354f163cfc5febc (patch) | |
tree | ba1bb6423431a8aa2804113140f30f9676a5a33d /src/cmdline.cpp | |
parent | 80bc1c0716e0ba7f9ebc89670576f6fe558d3d53 (diff) | |
download | sciteco-a3a340a9e9e1856a46c079186354f163cfc5febc.tar.gz |
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.
Diffstat (limited to 'src/cmdline.cpp')
-rw-r--r-- | src/cmdline.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
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); |