From: Daniel Carl Date: Mon, 24 Dec 2012 02:29:23 +0000 (+0100) Subject: Allow to yank hinted link url. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=0ce4ec6550966a0a3037f5534342a2acf0f408fb;p=vimb.git Allow to yank hinted link url. --- diff --git a/doc/config b/doc/config index 89dbe81..dda7453 100644 --- a/doc/config +++ b/doc/config @@ -27,6 +27,7 @@ nmap f hint-link nmap F hint-link-new nmap ;o hint-input-open nmap ;t hint-input-tabopen +nmap ;y hint-yank nmap y yank-uri nmap Y yank-selection cmap complete diff --git a/src/command.c b/src/command.c index 247bb80..d94a14b 100644 --- a/src/command.c +++ b/src/command.c @@ -68,6 +68,7 @@ static CommandInfo cmd_list[] = { {"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-yank", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_YANK, ";y"}, VP_MODE_HINTING}, {"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING}, {"hint-focus-prev", command_hints_focus, {1}, VP_MODE_HINTING}, {"yank-uri", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}, VP_MODE_NORMAL}, @@ -300,24 +301,34 @@ gboolean command_yank(const Arg* arg) text = gtk_clipboard_wait_for_text(SECONDARY_CLIPBOARD()); } if (text) { + /* TODO is this the rigth place to switch the focus */ + gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview)); vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", text); g_free(text); return TRUE; } + + return FALSE; + } + /* use current arg.s a new clipboard content */ + Arg a = {arg->i}; + if (arg->i & COMMAND_YANK_URI) { + /* yank current url */ + a.s = g_strdup(CURRENT_URL()); } else { - /* use current arg.s a new clipboard content */ - Arg a = {arg->i, arg->s}; - if (arg->i & COMMAND_YANK_URI) { - /* yank current url */ - a.s = (gchar*)CURRENT_URL(); - } - if (vp_set_clipboard(&a)) { - vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", a.s); + a.s = arg->s ? g_strdup(arg->s) : NULL; + } + if (a.s) { + vp_set_clipboard(&a); + /* TODO is this the rigth place to switch the focus */ + gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview)); + vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", a.s); + g_free(a.s); - return TRUE; - } + return TRUE; } + return FALSE; } diff --git a/src/hints.c b/src/hints.c index 213dd5d..90e93c5 100644 --- a/src/hints.c +++ b/src/hints.c @@ -389,6 +389,12 @@ static void hints_process_fired_hint(guint mode, const gchar* uri) case HINTS_PROCESS_YANK: /* TODO not implemented */ + a.i = COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY; + a.s = g_strdup(uri); + command_yank(&a); + g_free(a.s); + /* TODO add a command that do the mode switching instead */ + vp_set_mode(VP_MODE_NORMAL, FALSE); break; } } diff --git a/src/hints.h b/src/hints.h index b5390b0..a911978 100644 --- a/src/hints.h +++ b/src/hints.h @@ -51,7 +51,7 @@ enum { typedef enum { HINTS_PROCESS_INPUT = (1 << 4), - HINTS_PROCESS_YANK + HINTS_PROCESS_YANK = (1 << 5), } HintsProcess; void hints_init(void);