summaryrefslogtreecommitdiff
path: root/src/input_handler.hh
diff options
context:
space:
mode:
authorNicolas Ouellet-Payeur <nicolaso@google.com>2020-02-27 10:36:15 -0500
committerNicolas Ouellet-payeur <nicolaso@google.com>2020-02-27 10:36:15 -0500
commit10d887583fc420617cfa70d826d3ada535eb1abb (patch)
tree5d162e99b458a2040478a3b6815300c7ff4ec2bf /src/input_handler.hh
parent97e5e75d4c0eea3036ecc0127ccf146b68d0746d (diff)
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
Diffstat (limited to 'src/input_handler.hh')
-rw-r--r--src/input_handler.hh13
1 files changed, 9 insertions, 4 deletions
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<AutoComplete>)
});
}
+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<typename Cmd>
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);
});
}