aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-08-02 17:58:37 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-08-08 13:55:49 -0700
commit97f1a8fe91abeda594945648c11b7f399df45135 (patch)
tree5737e5c2e721b08fb5cfc7949a18a2f8f4d3d1bb /src
parent0ac9f159d6b8235195d63f1669ca33dbc2474f47 (diff)
Factor the completion prefix behavior into its own function
In a few places, we need to add a prefix to completions that replace the token. This change factors that logic into its own function prepend_token_prefix.
Diffstat (limited to 'src')
-rw-r--r--src/complete.cpp15
-rw-r--r--src/complete.h3
-rw-r--r--src/fish_tests.cpp5
-rw-r--r--src/wildcard.cpp12
4 files changed, 22 insertions, 13 deletions
diff --git a/src/complete.cpp b/src/complete.cpp
index 24e0688b..2e4d69ce 100644
--- a/src/complete.cpp
+++ b/src/complete.cpp
@@ -326,6 +326,13 @@ bool completion_t::is_alphabetically_equal_to(const completion_t &a, const compl
return a.completion == b.completion;
}
+void completion_t::prepend_token_prefix(const wcstring &prefix)
+{
+ if (this->flags & COMPLETE_REPLACES_TOKEN)
+ {
+ this->completion.insert(0, prefix);
+ }
+}
/** Class representing an attempt to compute completions */
class completer_t
@@ -1647,15 +1654,11 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file, bool
debug(3, L"Error while expanding string '%ls'", sep_string.c_str());
}
- /* Hack hack hack. Any COMPLETE_REPLACES_TOKEN will also stomp the separator. We need to "repair" them by inserting our separator and prefix. */
+ /* Any COMPLETE_REPLACES_TOKEN will also stomp the separator. We need to "repair" them by inserting our separator and prefix. */
const wcstring prefix_with_sep = wcstring(str, 0, sep_index + 1);
for (size_t i=0; i < local_completions.size(); i++)
{
- completion_t *c = &local_completions.at(i);
- if (c->flags & COMPLETE_REPLACES_TOKEN)
- {
- c->completion.insert(0, prefix_with_sep);
- }
+ local_completions.at(i).prepend_token_prefix(prefix_with_sep);
}
this->completions.insert(this->completions.end(),
local_completions.begin(),
diff --git a/src/complete.h b/src/complete.h
index 466ddbe9..deb0c42a 100644
--- a/src/complete.h
+++ b/src/complete.h
@@ -125,6 +125,9 @@ public:
/* "Naturally less than" means in a natural ordering, where digits are treated as numbers. For example, foo10 is naturally greater than foo2 (but alphabetically less than it) */
static bool is_naturally_less_than(const completion_t &a, const completion_t &b);
static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
+
+ /* If this completion replaces the entire token, prepend a prefix. Otherwise do nothing. */
+ void prepend_token_prefix(const wcstring &prefix);
};
enum
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
index 157ee5ab..5df91f1d 100644
--- a/src/fish_tests.cpp
+++ b/src/fish_tests.cpp
@@ -1475,6 +1475,11 @@ static void test_expand()
L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax", L"/tmp/fish_expand_test/bax/xxx", L"/tmp/fish_expand_test/baz", L"/tmp/fish_expand_test/baz/xxx", wnull,
L"Glob did the wrong thing");
+ expand_test(L"/tmp/fish_expand_test/BA", FOR_COMPLETIONS,
+ L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax/", L"/tmp/fish_expand_test/baz/", wnull,
+ L"Case insensitive test did the wrong thing");
+
+
if (! expand_test(L"/tmp/fish_expand_test/.*", 0, L"/tmp/fish_expand_test/.foo", 0))
{
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index 6b90e6b0..6cbf2d1e 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -826,6 +826,7 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas
}
else
{
+ // Normal wildcard expansion, not for completions
if (wildcard_match(name_str, wc, true /* skip files with leading dots */))
{
const wcstring abs_path = base_dir + name_str;
@@ -1277,13 +1278,10 @@ static int wildcard_expand(const wchar_t *wc,
for (size_t i=c; i<out->size(); i++)
{
completion_t &c = out->at(i);
-
- if (c.flags & COMPLETE_REPLACES_TOKEN)
- {
- // completion = base_dir + wc_base + completion
- c.completion.insert(0, wc_base);
- c.completion.insert(0, base_dir);
- }
+
+ // completion = base_dir + wc_base + completion
+ c.prepend_token_prefix(wc_base);
+ c.prepend_token_prefix(base_dir);
}
}
if (expander.interrupted())