From 1c59a3f1a8fddf366e2c6c14fe1061d26f4b8cc0 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 16 Aug 2018 14:07:38 -0500 Subject: [PATCH] Fix traversal order of tokens in history completion Fixes an issue introduced by e51e854. Closes #5150. --- src/reader.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index b449174f6..27d13cc42 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -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 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; }