Skip to content

Commit

Permalink
Allow link activation from search result #131.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fanglingsu committed Aug 31, 2016
1 parent b2a2125 commit 8e28af1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/vimb.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion src/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e28af1

Please sign in to comment.