diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-05-12 21:25:08 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-05-17 19:52:22 +1000 |
| commit | c972dfd2d7875dd3780d4abd4ef0df0c09be421a (patch) | |
| tree | e726e886af03dff4989d20d3e5af54da286980e9 /src/input_handler.cc | |
| parent | 4916471029dfa9853473679823bf557bad2c4a52 (diff) | |
Introduce Menu completion flags to auto select best candidate
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 275bc1f0..58b8d0d2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -780,6 +780,15 @@ public: if (key == Key::Return) { + if ((m_completions.flags & Completions::Flags::Menu) and + m_current_completion == -1 and + not m_completions.candidates.empty()) + { + const String& completion = m_completions.candidates.front(); + m_line_editor.insert_from(line.char_count_to(m_completions.start), + completion); + } + if (not context().history_disabled()) history_push(history, line); context().print_status(DisplayLine{}); @@ -1001,6 +1010,7 @@ private: const String& line = m_line_editor.line(); m_completions = m_completer(context(), flags, line, line.byte_count_to(m_line_editor.cursor_pos())); + const bool menu = (bool)(m_completions.flags & Completions::Flags::Menu); if (context().has_client()) { if (m_completions.candidates.empty()) @@ -1013,8 +1023,11 @@ private: const auto menu_style = (m_flags & PromptFlags::Search) ? MenuStyle::Search : MenuStyle::Prompt; context().client().menu_show(items, {}, menu_style); + if (menu) + context().client().menu_select(0); + auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start); - if (not contains(m_completions.candidates, prefix)) + if (not menu and not contains(m_completions.candidates, prefix)) { m_current_completion = m_completions.candidates.size(); m_completions.candidates.push_back(prefix.str()); |
