From cb8dd5480429caadebba2da5973a0831b079c44c Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 13 Jul 2014 21:57:44 +0200 Subject: [PATCH] Fire ambiguous numeric hints after hint-timeout. --- doc/vimb.1 | 4 ++++ src/hints.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/setting.c | 2 ++ 3 files changed, 46 insertions(+) diff --git a/doc/vimb.1 b/doc/vimb.1 index edcd6bb..31c87b2 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -852,6 +852,10 @@ Header completely from request. .PD .RE .TP +.B hint-timeout (int) +Timeout before automatically following a non-unique numerical hint. To disable +auto fire of hints, set this value to 0. +.TP .B history-max-items (int) Maximum number of unique items stored in search-, command or URI history. If history-max-items is set to 0, the history file will not be changed. diff --git a/src/hints.c b/src/hints.c index f4c85d2..746c56b 100644 --- a/src/hints.c +++ b/src/hints.c @@ -21,6 +21,7 @@ #include #include #include "hints.h" +#include "main.h" #include "ascii.h" #include "dom.h" #include "command.h" @@ -43,11 +44,14 @@ static struct { * have to change to open windows via hinting */ gboolean allow_open_win; #endif + guint timeout_id; } hints; extern VbCore vb; static gboolean call_hints_function(const char *func, int count, JSValueRef params[]); +static void fire_timeout(gboolean on); +static gboolean fire_cb(gpointer data); void hints_init(WebKitWebFrame *frame) @@ -77,25 +81,31 @@ VbResult hints_keypress(int key) return RESULT_COMPLETE; } else if (key == CTRL('H')) { + fire_timeout(false); arguments[0] = JSValueMakeNull(hints.ctx); if (call_hints_function("update", 1, arguments)) { return RESULT_COMPLETE; } } else if (VB_IS_DIGIT(key)) { + fire_timeout(true); + arguments[0] = JSValueMakeNumber(hints.ctx, key - '0'); if (call_hints_function("update", 1, arguments)) { return RESULT_COMPLETE; } } else if (key == KEY_TAB) { + fire_timeout(false); hints_focus_next(false); return RESULT_COMPLETE; } else if (key == KEY_SHIFT_TAB) { + fire_timeout(false); hints_focus_next(true); return RESULT_COMPLETE; } + fire_timeout(false); return RESULT_ERROR; } @@ -281,15 +291,18 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para /* following return values mark fired hints */ if (!strncmp(value, "DONE:", 5)) { + fire_timeout(false); if (!hints.gmode) { mode_enter('n'); } } else if (!strncmp(value, "INSERT:", 7)) { + fire_timeout(false); mode_enter('i'); if (hints.mode == 'e') { input_open_editor(); } } else if (!strncmp(value, "DATA:", 5)) { + fire_timeout(false); /* switch first to normal mode - else we would clear the inputbox * on switching mode also if we want to show yanked data */ if (!hints.gmode) { @@ -347,3 +360,30 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para g_free(value); return true; } + +static void fire_timeout(gboolean on) +{ + int millis; + /* remove possible timeout function */ + if (hints.timeout_id) { + g_source_remove(hints.timeout_id); + hints.timeout_id = 0; + } + + if (on) { + millis = GET_INT("hint-timeout"); + if (millis) { + hints.timeout_id = g_timeout_add(millis, (GSourceFunc)fire_cb, NULL); + } + } +} + +static gboolean fire_cb(gpointer data) +{ + hints_fire(); + + /* remove timeout id for the timeout that is removed by return value of + * false automatic */ + hints.timeout_id = 0; + return false; +} diff --git a/src/setting.c b/src/setting.c index 0eca036..0629eaa 100644 --- a/src/setting.c +++ b/src/setting.c @@ -127,6 +127,8 @@ void setting_init() setting_add("completion-bg-active", TYPE_COLOR, &"#777777", input_color, &vb.style.comp_bg[VB_COMP_ACTIVE]); setting_add("ca-bundle", TYPE_CHAR, &"/etc/ssl/certs/ca-certificates.crt", ca_bundle, NULL); setting_add("home-page", TYPE_CHAR, &SETTING_HOME_PAGE, NULL, NULL); + i = 1000; + setting_add("hint-timeout", TYPE_INTEGER, &i, NULL, NULL); setting_add("download-path", TYPE_CHAR, &"", internal, &vb.config.download_dir); i = 2000; setting_add("history-max-items", TYPE_INTEGER, &i, internal, &vb.config.history_max); -- 2.20.1