Fix traversal order of tokens in history completion

Fixes an issue introduced by e51e854. Closes #5150.
This commit is contained in:
Mahmoud Al-Qudsi 2018-08-16 14:07:38 -05:00
parent e8a35bfaa8
commit 1c59a3f1a8

View file

@ -187,13 +187,20 @@ class reader_history_search_t {
const wcstring &needle = search_string();
tokenizer_t tok(text.c_str(), TOK_ACCEPT_UNFINISHED);
tok_t token;
std::vector<wcstring> local_tokens;
while (tok.next(&token)) {
if (token.type != TOK_STRING) continue;
wcstring text = tok.text_of(token);
if (text.find(needle) != wcstring::npos) {
add_if_new(std::move(text));
local_tokens.emplace_back(std::move(text));
}
}
// Make sure tokens are added in reverse order. See #5150
for (auto i = local_tokens.rbegin(); i != local_tokens.rend(); ++i) {
add_if_new(std::move(*i));
}
}
return matches_.size() > before;
}