From 10d887583fc420617cfa70d826d3ada535eb1abb Mon Sep 17 00:00:00 2001 From: Nicolas Ouellet-Payeur Date: Thu, 27 Feb 2020 10:36:15 -0500 Subject: Make `on_next_key_with_autoinfo()` respect `idle_timeout` The prompt and autocomplete normally wait for `idle_timeout` before showing suggestions, however commands like `g`, `v`, or the lead-key show Clippy instantly. This fixes the issue by making `on_next_key_with_autoinfo()` wait for `idle_timeout` before displaying suggestions. Fixes mawww/kakoune#3365 Fixes mawww/kakoune#2066 --- src/input_handler.hh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/input_handler.hh') diff --git a/src/input_handler.hh b/src/input_handler.hh index 3638785b..8c93c141 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -11,6 +11,7 @@ #include "utils.hh" #include "safe_ptr.hh" #include "display_buffer.hh" +#include "event_manager.hh" namespace Kakoune { @@ -80,7 +81,8 @@ public: // execute callback on next keypress and returns to normal mode // if callback does not change the mode itself - void on_next_key(StringView mode_name, KeymapMode mode, KeyCallback callback); + void on_next_key(StringView mode_name, KeymapMode mode, KeyCallback callback, + Timer::Callback idle_callback = Timer::Callback{}); // process the given key void handle_key(Key key); @@ -171,19 +173,22 @@ constexpr auto enum_desc(Meta::Type) }); } +bool should_show_info(AutoInfo mask, const Context& context); bool show_auto_info_ifn(StringView title, StringView info, AutoInfo mask, const Context& context); void hide_auto_info_ifn(const Context& context, bool hide); template void on_next_key_with_autoinfo(const Context& context, StringView mode_name, KeymapMode keymap_mode, Cmd cmd, - StringView title, StringView info) + String title, String info) { - const bool hide = show_auto_info_ifn(title, info, AutoInfo::OnKey, context); context.input_handler().on_next_key(mode_name, - keymap_mode, [hide,cmd](Key key, Context& context) mutable { + keymap_mode, [cmd](Key key, Context& context) mutable { + bool hide = should_show_info(AutoInfo::OnKey, context); hide_auto_info_ifn(context, hide); cmd(key, context); + }, [&context, title=std::move(title), info=std::move(info)](Timer&) { + show_auto_info_ifn(title, info, AutoInfo::OnKey, context); }); } -- cgit v1.2.3