From: Daniel Carl Date: Sun, 14 Apr 2013 19:53:12 +0000 (+0200) Subject: Added new hinting mode to open form fields with editor (#15). X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=a0889c549896ea1c1ca541530143e19526023ac4;p=vimb.git Added new hinting mode to open form fields with editor (#15). --- diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index caf0001..ad4adce 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -256,6 +256,10 @@ clipboard. If \fIPREFIX\fP is given, print this into the inputbox, default ';y'. Start hinting to open images into current or new window. If \fIPREFIX\fP is given, print this into the inputbox, default ';i' and ';I'. .TP +.BI "hint-editor [" PREFIX "]" +Start hinting to open inputboxes or textareas with external editor. If +\fIPREFIX\fP is given, print this into the inputbox, default ';e'. +.TP .B hint-focus-nex, hint-focus-prevt Focus next or previous hint. .SS Yank @@ -477,6 +481,9 @@ Start hinting to open images. .B ;\-I Start hinting to open images into new window. .TP +.B ;\-e +Start hinting to open editable form fileds with external editor. +.TP .B y Yank the URI or current page into clipboard. .TP diff --git a/src/command.c b/src/command.c index 48cf36c..df05a23 100644 --- a/src/command.c +++ b/src/command.c @@ -88,6 +88,7 @@ static CommandInfo cmd_list[] = { {"hint-yank", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_YANK, ";y"}}, {"hint-image-open", command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN, ";i"}}, {"hint-image-tabopen", command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN | HINTS_OPEN_NEW, ";I"}}, + {"hint-editor", command_hints, {HINTS_TYPE_EDITABLE, ";e"}}, {"hint-focus-next", command_hints_focus, {0}}, {"hint-focus-prev", command_hints_focus, {1}}, {"yank-uri", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}}, diff --git a/src/config.h b/src/config.h index 325cf2c..15e0072 100644 --- a/src/config.h +++ b/src/config.h @@ -75,6 +75,7 @@ const char *default_config[] = { "nmap ;y=hint-yank", "nmap ;i=hint-image-open", "nmap ;I=hint-image-tabopen", + "nmap ;e=hint-editor", "nmap y=yank-uri", "nmap Y=yank-selection", "nmap p=open-clipboard", diff --git a/src/hints.c b/src/hints.c index 5ca08fb..bbab0dd 100644 --- a/src/hints.c +++ b/src/hints.c @@ -79,7 +79,13 @@ void hints_create(const char *input, guint mode, const guint prefixLength) char type, usage; /* convert the mode into the type chare used in the hint script */ - type = mode & HINTS_TYPE_LINK ? 'l' : 'i'; + if (HINTS_GET_TYPE(mode) == HINTS_TYPE_LINK) { + type = 'l'; + } else if (HINTS_GET_TYPE(mode) == HINTS_TYPE_EDITABLE) { + type = 'e'; + } else { + type = 'i'; + } if (mode & HINTS_PROCESS_OPEN) { usage = mode & HINTS_OPEN_NEW ? 'T' : 'O'; @@ -148,6 +154,9 @@ static void run_script(char *js) vb_set_mode(VB_MODE_NORMAL, true); } else if (!strncmp(value, "INSERT:", 7)) { vb_set_mode(VB_MODE_INSERT, false); + if (HINTS_GET_TYPE(mode) == HINTS_TYPE_EDITABLE) { + command_editor(NULL); + } } else if (!strncmp(value, "DATA:", 5)) { Arg a = {0}; char *v = (value + 5); diff --git a/src/hints.h b/src/hints.h index 17ef146..5146036 100644 --- a/src/hints.h +++ b/src/hints.h @@ -22,11 +22,12 @@ #include "main.h" -#define HINTS_GET_TYPE(n) ((n) & (HINTS_TYPE_LINK | HINTS_TYPE_IMAGE)) +#define HINTS_GET_TYPE(n) ((n) & (HINTS_TYPE_LINK | HINTS_TYPE_IMAGE | HINTS_TYPE_EDITABLE)) enum { HINTS_TYPE_LINK = 1, HINTS_TYPE_IMAGE = 2, + HINTS_TYPE_EDITABLE = 3, HINTS_PROCESS_INPUT = (1 << 2), HINTS_PROCESS_YANK = (1 << 3), HINTS_PROCESS_OPEN = (1 << 4), diff --git a/src/hints.js b/src/hints.js index b00aebb..224426f 100644 --- a/src/hints.js +++ b/src/hints.js @@ -1,4 +1,4 @@ -/* mode: l - links, i - images */ +/* mode: l - links, i - images, e - editables */ /* usage: O - open, T - open in new window, U - use source */ function VimbHints(mode, usage, bg, bgf, fg, style, maxHints) { @@ -334,6 +334,12 @@ function VimbHints(mode, usage, bg, bgf, fg, style, maxHints) } else { return "//*[(@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href) and contains(., '" + s + "')] | //input[not(@type='hidden') and contains(., '" + s + "')] | //a[@href and contains(., '" + s + "')] | //area[contains(., '" + s + "')] | //textarea[contains(., '" + s + "')] | //button[contains(@value, '" + s + "')] | //select[contains(., '" + s + "')]"; } + case "e": + if (s === "") { + return "//input[@type='text'] | //textarea"; + } else { + return "//input[@type='text' and contains(., '" + s + "')] | //textarea[contains(., '" + s + "')]"; + } case "i": if (s === "") { return "//img[@src]";