Fix for extra space when tab completing directories. Fixes #1241

This commit is contained in:
ridiculousfish 2014-01-14 14:28:06 -08:00
parent 28c7094f5b
commit c22d94bba6
2 changed files with 21 additions and 14 deletions

View file

@ -281,21 +281,26 @@ completion_t::~completion_t()
{ {
} }
/* completion_t functions */ /* Clear the COMPLETE_AUTO_SPACE flag, and set COMPLETE_NO_SPACE appropriately depending on the suffix of the string */
completion_t::completion_t(const wcstring &comp, const wcstring &desc, string_fuzzy_match_t mat, int flags_val) : static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_t flags)
completion(comp),
description(desc),
match(mat),
flags(flags_val)
{ {
if (flags & COMPLETE_AUTO_SPACE) if (flags & COMPLETE_AUTO_SPACE)
{ {
flags = flags & ~COMPLETE_AUTO_SPACE; flags = flags & ~COMPLETE_AUTO_SPACE;
size_t len = completion.size(); size_t len = comp.size();
if (len > 0 && (wcschr(L"/=@:", comp.at(len-1)) != 0)) if (len > 0 && (wcschr(L"/=@:", comp.at(len-1)) != 0))
flags |= COMPLETE_NO_SPACE; flags |= COMPLETE_NO_SPACE;
} }
return flags;
}
/* completion_t functions. Note that the constructor resolves flags! */
completion_t::completion_t(const wcstring &comp, const wcstring &desc, string_fuzzy_match_t mat, complete_flags_t flags_val) :
completion(comp),
description(desc),
match(mat),
flags(resolve_auto_space(comp, flags_val))
{
} }
completion_t::completion_t(const completion_t &him) : completion(him.completion), description(him.description), match(him.match), flags(him.flags) completion_t::completion_t(const completion_t &him) : completion(him.completion), description(him.description), match(him.match), flags(him.flags)
@ -463,16 +468,18 @@ void completion_autoload_t::command_removed(const wcstring &cmd)
} }
/** Create a new completion entry */ /** Create a new completion entry. */
void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc, complete_flags_t flags, string_fuzzy_match_t match) void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc, complete_flags_t flags, string_fuzzy_match_t match)
{ {
/* If we just constructed the completion and used push_back, we would get two string copies. Try to avoid that by making a stubby completion in the vector first, and then copying our string in. */ /* If we just constructed the completion and used push_back, we would get two string copies. Try to avoid that by making a stubby completion in the vector first, and then copying our string in. Note that completion_t's constructor will munge 'flags' so it's important that we pass those to the constructor.
completions.push_back(completion_t(wcstring()));
Nasty hack for #1241 - since the constructor needs the completion string to resolve AUTO_SPACE, and we aren't providing it with the completion, we have to do the resolution ourselves. We should get this resolving out of the constructor.
*/
const wcstring empty;
completions.push_back(completion_t(empty, empty, match, resolve_auto_space(comp, flags)));
completion_t *last = &completions.back(); completion_t *last = &completions.back();
last->completion = comp; last->completion = comp;
last->description = desc; last->description = desc;
last->match = match;
last->flags = flags;
} }
/** /**

View file

@ -121,10 +121,10 @@ public:
The COMPLETE_NO_CASE can be used to signal that this completion The COMPLETE_NO_CASE can be used to signal that this completion
is case insensitive. is case insensitive.
*/ */
int flags; complete_flags_t flags;
/* Construction. Note: defining these so that they are not inlined reduces the executable size. */ /* Construction. Note: defining these so that they are not inlined reduces the executable size. */
completion_t(const wcstring &comp, const wcstring &desc = wcstring(), string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), int flags_val = 0); completion_t(const wcstring &comp, const wcstring &desc = wcstring(), string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), complete_flags_t flags_val = 0);
completion_t(const completion_t &); completion_t(const completion_t &);
completion_t &operator=(const completion_t &); completion_t &operator=(const completion_t &);