diff options
| author | Maxime Coste <mawww@kakoune.org> | 2022-06-04 10:50:09 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2022-06-04 10:50:09 +1000 |
| commit | 6ffec7540666702ea3b96a2efa3a32006ff7ad47 (patch) | |
| tree | fb358cbc42c8fd74a9bd68e3c0223ddd834db262 /src/insert_completer.cc | |
| parent | a16de52f9cd929c05a0211ac0b19c6fa116bd524 (diff) | |
Code style cleanups around insert completer
Diffstat (limited to 'src/insert_completer.cc')
| -rw-r--r-- | src/insert_completer.cc | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc index d06df6f0..dd048733 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -474,38 +474,40 @@ void InsertCompleter::update(bool allow_implicit) auto& get_first(BufferRange& range) { return range.begin; } auto& get_last(BufferRange& range) { return range.end; } +bool InsertCompleter::has_candidate_selected() const +{ + return m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1; +} + void InsertCompleter::try_accept() { - if (m_completions.is_valid() and m_context.has_client() - and m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1) - { + if (m_completions.is_valid() and m_context.has_client() and has_candidate_selected()) reset(); - } } void InsertCompleter::reset() { - if (m_explicit_completer or m_completions.is_valid()) + if (not m_explicit_completer and not m_completions.is_valid()) + return; + + String hook_param; + if (m_context.has_client() and has_candidate_selected()) { - String hook_param; - if (m_context.has_client() and m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1) - { - auto& buffer = m_context.buffer(); - update_ranges(buffer, m_completions.timestamp, m_inserted_ranges); - hook_param = join(m_inserted_ranges | filter([](auto&& r) { return not r.empty(); }) | transform([&](auto&& r) { - return selection_to_string(ColumnType::Byte, buffer, {r.begin, buffer.char_prev(r.end)}); - }), ' '); - } + auto& buffer = m_context.buffer(); + update_ranges(buffer, m_completions.timestamp, m_inserted_ranges); + hook_param = join(m_inserted_ranges | filter([](auto&& r) { return not r.empty(); }) | transform([&](auto&& r) { + return selection_to_string(ColumnType::Byte, buffer, {r.begin, buffer.char_prev(r.end)}); + }), ' '); + } - m_explicit_completer = nullptr; - m_completions = InsertCompletion{}; - m_inserted_ranges.clear(); - if (m_context.has_client()) - { - m_context.client().menu_hide(); - m_context.client().info_hide(); - m_context.hooks().run_hook(Hook::InsertCompletionHide, hook_param, m_context); - } + m_explicit_completer = nullptr; + m_completions = InsertCompletion{}; + m_inserted_ranges.clear(); + if (m_context.has_client()) + { + m_context.client().menu_hide(); + m_context.client().info_hide(); + m_context.hooks().run_hook(Hook::InsertCompletionHide, hook_param, m_context); } } |
