From cf2609de1ce80e069045bc4f567c79d22345ca39 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Jun 2014 13:44:45 +0100 Subject: [PATCH] Tweak prompt completion behaviour Always select the common prefix if we just updated the list of completions. The previous behaviour was to ignore it if we had it already typed. Do that only if it was already displayed. --- src/input_handler.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 523a1660..ee136e24 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -451,12 +451,14 @@ public: const bool reverse = (key == Key::BackTab); CandidateList& candidates = m_completions.candidates; // first try, we need to ask our completer for completions + bool updated_completions = false; if (candidates.empty()) { refresh_completions(CompletionFlags::None); if (candidates.empty()) return; + updated_completions = true; } bool did_prefix = false; if (m_current_completion == -1 and @@ -481,7 +483,10 @@ public: m_current_completion = it - candidates.begin(); CharCount start = line.char_count_to(m_completions.start); - did_prefix = prefix != line.substr(start, m_line_editor.cursor_pos() - start); + // When we just updated completions, select the common + // prefix even if it was the currently entered text. + did_prefix = updated_completions or + prefix != line.substr(start, m_line_editor.cursor_pos() - start); } } if (not did_prefix) @@ -545,6 +550,7 @@ private: { if (not m_completer) return; + m_current_completion = -1; const String& line = m_line_editor.line(); m_completions = m_completer(context(), flags, line, line.byte_count_to(m_line_editor.cursor_pos()));