diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-05-03 22:22:12 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-05-03 22:28:20 +1000 |
| commit | 7325ad216cbecb0d14fdee40cef7cca3e39f8513 (patch) | |
| tree | ad23b0afd3ad24fbf8bde23bcd4bba426d52a046 /src/input_handler.cc | |
| parent | c2637f08d95b03fbe6db5b0f98b28c2a54fd4126 (diff) | |
Add support for explicit menu selection from the UI
the JsonUI now supports a "menu_select(int)" RPC call that should
trigger explicit selection of the provided item index.
As discussed for issue #2019.
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 9e4a8b50..ff6e126f 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -837,9 +837,8 @@ public: m_refresh_completion_pending = true; } } - else if (key == Key::Tab or key == shift(Key::Tab)) // tab completion + else if (key == Key::Tab or key == shift(Key::Tab) or key.modifiers == Key::Modifiers::MenuSelect) // completion { - const bool reverse = (key == shift(Key::Tab)); CandidateList& candidates = m_completions.candidates; // first try, we need to ask our completer for completions if (candidates.empty()) @@ -853,7 +852,10 @@ public: if (candidates.empty()) return; - if (not reverse and ++m_current_completion >= candidates.size()) + const bool reverse = (key == shift(Key::Tab)); + if (key.modifiers == Key::Modifiers::MenuSelect) + m_current_completion = clamp<int>(key.key, 0, candidates.size() - 1); + else if (not reverse and ++m_current_completion >= candidates.size()) m_current_completion = 0; else if (reverse and --m_current_completion < 0) m_current_completion = candidates.size()-1; @@ -1222,13 +1224,19 @@ public: else if (key == ctrl('n')) { last_insert().keys.pop_back(); - m_completer.select(1, last_insert().keys); + m_completer.select(1, true, last_insert().keys); update_completions = false; } else if (key == ctrl('p')) { last_insert().keys.pop_back(); - m_completer.select(-1, last_insert().keys); + m_completer.select(-1, true, last_insert().keys); + update_completions = false; + } + else if (key.modifiers == Key::Modifiers::MenuSelect) + { + last_insert().keys.pop_back(); + m_completer.select(key.key, false, last_insert().keys); update_completions = false; } else if (key == ctrl('x')) |
