mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Tweak try_add_completion_result logic
Preparation for zsh-style intermediate fuzzy matching
This commit is contained in:
parent
459df23931
commit
b7e16cb0dd
1 changed files with 8 additions and 12 deletions
|
@ -685,21 +685,19 @@ class wildcard_expander_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void try_add_completion_result(const wcstring &filepath, const wcstring &filename, const wchar_t *wildcard)
|
void try_add_completion_result(const wcstring &filepath, const wcstring &filename, const wcstring &wildcard)
|
||||||
{
|
{
|
||||||
/* This function is only for the completions case */
|
/* This function is only for the completions case */
|
||||||
assert(this->flags & EXPAND_FOR_COMPLETIONS);
|
assert(this->flags & EXPAND_FOR_COMPLETIONS);
|
||||||
size_t before = this->resolved_completions->size();
|
size_t before = this->resolved_completions->size();
|
||||||
if (wildcard_test_flags_then_complete(filepath, filename, wildcard, this->flags, this->resolved_completions))
|
if (wildcard_test_flags_then_complete(filepath, filename, wildcard.c_str(), this->flags, this->resolved_completions))
|
||||||
{
|
{
|
||||||
/* Hack. We added this completion result based on the last component of the wildcard.
|
/* Hack. We added this completion result based on the last component of the wildcard.
|
||||||
Prepend all prior components of the wildcard to each completion that replaces its token. */
|
Prepend all prior components of the wildcard to each completion that replaces its token. */
|
||||||
wcstring wc_base;
|
size_t wc_len = wildcard.size();
|
||||||
const wchar_t *wc_base_ptr = wcsrchr(this->original_wildcard, L'/');
|
size_t orig_wc_len = wcslen(this->original_wildcard);
|
||||||
if (wc_base_ptr)
|
assert(wc_len <= orig_wc_len);
|
||||||
{
|
const wcstring wc_base(this->original_wildcard, orig_wc_len - wc_len);
|
||||||
wc_base.assign(this->original_wildcard, wc_base_ptr+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t after = this->resolved_completions->size();
|
size_t after = this->resolved_completions->size();
|
||||||
for (size_t i=before; i < after; i++)
|
for (size_t i=before; i < after; i++)
|
||||||
|
@ -827,7 +825,7 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas
|
||||||
{
|
{
|
||||||
if (flags & EXPAND_FOR_COMPLETIONS)
|
if (flags & EXPAND_FOR_COMPLETIONS)
|
||||||
{
|
{
|
||||||
this->try_add_completion_result(base_dir + name_str, name_str, wc.c_str());
|
this->try_add_completion_result(base_dir + name_str, name_str, wc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -941,9 +939,7 @@ static int wildcard_expand(const wchar_t *wc,
|
||||||
expand_flags_t flags,
|
expand_flags_t flags,
|
||||||
std::vector<completion_t> *out)
|
std::vector<completion_t> *out)
|
||||||
{
|
{
|
||||||
assert(out != NULL);
|
assert(out != NULL);
|
||||||
size_t c = out->size();
|
|
||||||
|
|
||||||
wildcard_expander_t expander(base_dir, wc, flags, out);
|
wildcard_expander_t expander(base_dir, wc, flags, out);
|
||||||
expander.expand(base_dir, wc);
|
expander.expand(base_dir, wc);
|
||||||
return expander.status_code();
|
return expander.status_code();
|
||||||
|
|
Loading…
Reference in a new issue