Allow link activation from search result.
authorDaniel Carl <danielcarl@gmx.de>
Tue, 27 Sep 2016 22:29:27 +0000 (00:29 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 27 Sep 2016 22:29:27 +0000 (00:29 +0200)
When a search is performed and the current highlighted result is part of
a link, a click event is triggered on the link to open it. Currently
the click() is done by JavaScript on the element so that we can't
control if the target open in current window or in a new one.

src/command.c
src/normal.c

index 09ab5ef..9d97f42 100644 (file)
@@ -68,6 +68,7 @@ gboolean command_search(Client *c, const Arg *arg)
                     WEBKIT_FIND_OPTIONS_WRAP_AROUND |
                     (forward ?  WEBKIT_FIND_OPTIONS_NONE : WEBKIT_FIND_OPTIONS_BACKWARDS),
                     G_MAXUINT);
+            /* TODO get the number of matches */
             c->state.search.active = TRUE;
             /* Skip first search because the first match is already
              * highlighted on search start. */
index 3398488..7410fb9 100644 (file)
@@ -53,6 +53,7 @@ typedef VbResult (*NormalCommand)(Client *c, const NormalCmdInfo *info);
 static VbResult normal_clear_input(Client *c, const NormalCmdInfo *info);
 static VbResult normal_descent(Client *c, const NormalCmdInfo *info);
 static VbResult normal_ex(Client *c, const NormalCmdInfo *info);
+static VbResult normal_fire(Client *c, const NormalCmdInfo *info);
 static VbResult normal_g_cmd(Client *c, const NormalCmdInfo *info);
 static VbResult normal_hint(Client *c, const NormalCmdInfo *info);
 static VbResult normal_do_hint(Client *c, const char *prompt);
@@ -90,7 +91,7 @@ static struct {
 /* ^J  0x0a */ {NULL},
 /* ^K  0x0b */ {NULL},
 /* ^L  0x0c */ {NULL},
-/* ^M  0x0d */ {NULL},
+/* ^M  0x0d */ {normal_fire},
 /* ^N  0x0e */ {NULL},
 /* ^O  0x0f */ {normal_navigate},
 /* ^P  0x10 */ {normal_queue},
@@ -415,6 +416,22 @@ static VbResult normal_ex(Client *c, const NormalCmdInfo *info)
     return RESULT_COMPLETE;
 }
 
+static VbResult normal_fire(Client *c, const NormalCmdInfo *info)
+{
+    /* If searching is currently active - click link containing current search
+     * highlight. We use the search_matches as indicator that the searching is
+     * active. */
+    if (c->state.search.active) {
+        webkit_web_view_run_javascript(c->webview,
+                "getSelection().anchorNode.parentNode.click();", NULL, NULL,
+                NULL);
+
+        return RESULT_COMPLETE;
+    }
+
+    return RESULT_ERROR;
+}
+
 static VbResult normal_g_cmd(Client *c, const NormalCmdInfo *info)
 {
     Arg a;