Added new hinting mode to open form fields with editor (#15).
authorDaniel Carl <danielcarl@gmx.de>
Sun, 14 Apr 2013 19:53:12 +0000 (21:53 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 14 Apr 2013 19:54:28 +0000 (21:54 +0200)
doc/vimb.1.txt
src/command.c
src/config.h
src/hints.c
src/hints.h
src/hints.js

index caf0001..ad4adce 100644 (file)
@@ -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
index 48cf36c..df05a23 100644 (file)
@@ -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}},
index 325cf2c..15e0072 100644 (file)
@@ -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",
index 5ca08fb..bbab0dd 100644 (file)
@@ -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);
index 17ef146..5146036 100644 (file)
 
 #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),
index b00aebb..224426f 100644 (file)
@@ -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]";