From b0d72ebce00a23b19db179310e675a98189340c2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 24 Mar 2016 13:39:27 +0000 Subject: [PATCH] Support getting back to original prefix with tab/shift-tab in prompts Fixes #124 --- src/input_handler.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 874601c2..d3081ac9 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -765,7 +765,8 @@ public: if (candidates.empty()) { refresh_completions(CompletionFlags::None); - if (candidates.size() > 1) + if ((not m_prefix_in_completions and candidates.size() > 1) or + candidates.size() > 2) return; } @@ -786,7 +787,8 @@ public: // when we have only one completion candidate, make next tab complete // from the new content. - if (candidates.size() == 1) + if (candidates.size() == 1 or + (m_prefix_in_completions and candidates.size() == 2)) { m_current_completion = -1; candidates.clear(); @@ -845,6 +847,15 @@ private: for (auto& candidate : m_completions.candidates) items.push_back({ candidate, {} }); context().client().menu_show(items, {}, MenuStyle::Prompt); + + auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start); + if (not contains(m_completions.candidates, prefix)) + { + m_completions.candidates.push_back(prefix.str()); + m_prefix_in_completions = true; + } + else + m_prefix_in_completions = false; } } catch (runtime_error&) {} } @@ -876,6 +887,7 @@ private: Face m_prompt_face; Completions m_completions; int m_current_completion = -1; + bool m_prefix_in_completions = false; String m_prefix; LineEditor m_line_editor; bool m_autoshowcompl;