diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-03-24 13:39:27 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-03-24 13:39:27 +0000 |
| commit | b0d72ebce00a23b19db179310e675a98189340c2 (patch) | |
| tree | 78d41b1f4fefa67a882dcec6a916bd7621108332 /src | |
| parent | b02883a112066ed81b2c4e57688d70b25f34c1ef (diff) | |
Support getting back to original prefix with tab/shift-tab in prompts
Fixes #124
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_handler.cc | 16 |
1 files 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; |
