diff options
| -rw-r--r-- | src/input_handler.cc | 17 | ||||
| -rw-r--r-- | src/insert_completer.cc | 4 | ||||
| -rw-r--r-- | src/insert_completer.hh | 3 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 85a8fbc1..0693bc43 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1303,15 +1303,19 @@ public: selections.sort_and_merge_overlapping(); } else if (auto cp = key.codepoint()) + { + m_completer.try_accept(); insert(*cp); + } else if (key == ctrl('r')) { + m_completer.try_accept(); on_next_key_with_autoinfo(context(), "register", KeymapMode::None, [this](Key key, Context&) { auto cp = key.codepoint(); if (not cp or key == Key::Escape) return; - insert([&] { return RegisterManager::instance()[*cp].get(context()); }); + insert(RegisterManager::instance()[*cp].get(context())); }, "enter register name", register_doc.str()); update_completions = false; } @@ -1359,6 +1363,7 @@ public: } else if (key == ctrl('v')) { + m_completer.try_accept(); on_next_key_with_autoinfo(context(), "raw-insert", KeymapMode::None, [this, transient](Key key, Context&) { if (auto cp = get_raw_codepoint(key)) @@ -1387,6 +1392,7 @@ public: void paste(StringView content) override { + m_completer.try_accept(); insert(ConstArrayView<StringView>{content}); m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context())); } @@ -1424,20 +1430,13 @@ private: template<typename S> void insert(ConstArrayView<S> strings) { - m_completer.try_accept(); + kak_assert(not m_completer.has_candidate_selected()); context().selections().for_each([strings, &buffer=context().buffer()] (size_t index, Selection& sel) { Kakoune::insert(buffer, sel, sel.cursor(), strings[std::min(strings.size()-1, index)]); }, false); } - template<std::invocable Func> - void insert(Func&& lazy_strings) - { - m_completer.try_accept(); - insert(std::forward<Func>(lazy_strings)()); - } - void insert(Codepoint key) { String str{key}; diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 1e83a47e..49bbd4ca 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -481,12 +481,12 @@ 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; + return m_completions.is_valid() and m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1; } void InsertCompleter::try_accept() { - if (m_completions.is_valid() and has_candidate_selected()) + if (has_candidate_selected()) reset(); } diff --git a/src/insert_completer.hh b/src/insert_completer.hh index c624639d..713cdedb 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -90,6 +90,8 @@ public: void explicit_line_buffer_complete(); void explicit_line_all_complete(); + bool has_candidate_selected() const; + private: bool setup_ifn(); @@ -98,7 +100,6 @@ private: void on_option_changed(const Option& opt) override; void menu_show(); - bool has_candidate_selected() const; Context& m_context; OptionManager& m_options; |
