From fe4450e579a40e6d8605c193a14d4a3e13ac4c91 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sat, 22 Dec 2012 16:30:07 +0100 Subject: [PATCH] Handle hinting command prefixes. This patch allow to have hinting command prefixes with differen length like ',' or ';t'. --- src/command.c | 6 +++--- src/hints.c | 22 ++++++++++++++-------- src/hints.h | 2 +- src/main.h | 1 + 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/command.c b/src/command.c index b159c6c..edcf92a 100644 --- a/src/command.c +++ b/src/command.c @@ -64,8 +64,8 @@ static CommandInfo cmd_list[] = { {"complete", command_complete, {0}, VP_MODE_COMMAND | VP_MODE_COMPLETE}, {"complete-back", command_complete, {1}, VP_MODE_COMMAND | VP_MODE_COMPLETE}, {"inspect", command_inspect, {0}, VP_MODE_NORMAL}, - {"hint-link", command_hints, {HINTS_TYPE_LINK, ". "}, VP_MODE_HINTING}, - {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK, ", "}, VP_MODE_HINTING}, + {"hint-link", command_hints, {HINTS_TYPE_LINK, "."}, VP_MODE_HINTING}, + {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK, ","}, VP_MODE_HINTING}, {"hint-input-open", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";o"}, VP_MODE_HINTING}, {"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";t"}, VP_MODE_HINTING}, {"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING}, @@ -275,7 +275,7 @@ gboolean command_inspect(const Arg* arg) gboolean command_hints(const Arg* arg) { command_write_input(arg->s); - hints_create(NULL, arg->i); + hints_create(NULL, arg->i, (arg->s ? strlen(arg->s) : 0)); return TRUE; } diff --git a/src/hints.c b/src/hints.c index fa96871..2760977 100644 --- a/src/hints.c +++ b/src/hints.c @@ -73,9 +73,10 @@ void hints_init(void) { Hints* hints = &vp.hints; - hints->list = NULL; - hints->focusNum = 0; - hints->num = 0; + hints->list = NULL; + hints->focusNum = 0; + hints->num = 0; + hints->prefixLength = 0; } void hints_clear(void) @@ -107,14 +108,19 @@ void hints_clear(void) hints_observe_input(FALSE); } -void hints_create(const gchar* input, guint mode) +void hints_create(const gchar* input, guint mode, const guint prefixLength) { Hints* hints = &vp.hints; Document* doc; Window* win; - hints->mode = mode; hints_clear(); + hints->mode = mode; + + /* don't overwrite if zero */ + if (prefixLength) { + hints->prefixLength = prefixLength; + } doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(vp.gui.webview)); if (!doc) { @@ -145,7 +151,7 @@ void hints_update(const gulong num) if (num == 0) { /* recreate the hints */ - hints_create(NULL, hints->mode); + hints_create(NULL, hints->mode, 0); return; } @@ -507,8 +513,8 @@ static gboolean hints_changed_callback(GtkEditable *entry, gpointer data) { const gchar* text = GET_TEXT(); - /* skip hinting prefixes like '. ', ', ', ';y' ... */ - hints_create(text + 2, vp.hints.mode); + /* skip hinting prefixes like '.', ',', ';y' ... */ + hints_create(text + vp.hints.prefixLength, vp.hints.mode, 0); return TRUE; } diff --git a/src/hints.h b/src/hints.h index 00e70ab..b5390b0 100644 --- a/src/hints.h +++ b/src/hints.h @@ -55,7 +55,7 @@ typedef enum { } HintsProcess; void hints_init(void); -void hints_create(const gchar* input, guint mode); +void hints_create(const gchar* input, guint mode, const guint prefixLength); void hints_update(const gulong num); void hints_clear(void); void hints_focus_next(const gboolean back); diff --git a/src/main.h b/src/main.h index 3a5dd4d..1159946 100644 --- a/src/main.h +++ b/src/main.h @@ -222,6 +222,7 @@ typedef struct { gulong focusNum; gulong num; guint mode; + guint prefixLength; } Hints; /* core struct */ -- 2.20.1