Allow link activation from search result #131.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 31 Aug 2016 21:32:40 +0000 (23:32 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 31 Aug 2016 21:41:37 +0000 (23:41 +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.

doc/vimb.1
src/main.c
src/normal.c

index 857240f..9708bce 100644 (file)
@@ -371,6 +371,9 @@ direction.
 .BI [ N ]N
 Search for \fIN\fPnth previous search result depending on current search
 direction.
+.TP
+.B <CR>
+Perform a click on element containing the current highlighted search result.
 .SS Zooming
 .TP
 .BI [ N ]zi
index 09ed4d9..301a80d 100644 (file)
@@ -793,6 +793,9 @@ static void webview_load_status_cb(WebKitWebView *view, GParamSpec *pspec)
             dom_install_focus_blur_callbacks(webkit_web_frame_get_dom_document(frame));
             vb.state.done_loading_page = false;
 
+            /* Unset possible last search. */
+            command_search(&((Arg){0}));
+
             break;
 
         case WEBKIT_LOAD_FINISHED:
index 5321ca2..1032216 100644 (file)
@@ -24,6 +24,7 @@
 #include "ascii.h"
 #include "command.h"
 #include "hints.h"
+#include "js.h"
 #include "dom.h"
 #include "history.h"
 #include "util.h"
@@ -56,6 +57,7 @@ static VbResult normal_focus_input(const NormalCmdInfo *info);
 static VbResult normal_g_cmd(const NormalCmdInfo *info);
 static VbResult normal_hint(const NormalCmdInfo *info);
 static VbResult normal_do_hint(const char *prompt);
+static VbResult normal_fire(const NormalCmdInfo *info);
 static VbResult normal_increment_decrement(const NormalCmdInfo *info);
 static VbResult normal_input_open(const NormalCmdInfo *info);
 static VbResult normal_mark(const NormalCmdInfo *info);
@@ -90,7 +92,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},
@@ -486,6 +488,24 @@ static VbResult normal_do_hint(const char *prompt)
     return RESULT_COMPLETE;
 }
 
+static VbResult normal_fire(const NormalCmdInfo *info)
+{
+    char *value = NULL;
+    /* If searching is currently active - click link containing current search
+     * highlight. We use the search_matches as indicator that the searching is
+     * active. */
+    if (vb.state.search_matches) {
+        js_eval(
+            webkit_web_frame_get_global_context(webkit_web_view_get_main_frame(vb.gui.webview)),
+            "getSelection().anchorNode.parentNode.click();", NULL, &value
+        );
+        g_free(value);
+
+        return RESULT_COMPLETE;
+    }
+    return RESULT_ERROR;
+}
+
 static VbResult normal_increment_decrement(const NormalCmdInfo *info)
 {
     int count = info->count ? info->count : 1;