Handle hinting command prefixes.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 22 Dec 2012 15:30:07 +0000 (16:30 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 22 Dec 2012 15:39:25 +0000 (16:39 +0100)
This patch allow to have hinting command prefixes with differen length like
',' or ';t'.

src/command.c
src/hints.c
src/hints.h
src/main.h

index b159c6c..edcf92a 100644 (file)
@@ -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;
 }
index fa96871..2760977 100644 (file)
@@ -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;
 }
index 00e70ab..b5390b0 100644 (file)
@@ -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);
index 3a5dd4d..1159946 100644 (file)
@@ -222,6 +222,7 @@ typedef struct {
     gulong focusNum;
     gulong num;
     guint  mode;
+    guint  prefixLength;
 } Hints;
 
 /* core struct */