Allow to focus last input field by 'i' #605.
authorDaniel Carl <danielcarl@gmx.de>
Fri, 28 Feb 2020 22:48:26 +0000 (23:48 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Fri, 28 Feb 2020 22:48:26 +0000 (23:48 +0100)
doc/vimb.1
src/normal.c

index 9305f45..9861af4 100644 (file)
@@ -95,6 +95,10 @@ Start Command Mode and print `:' to the input box.
 Set cursor to the first editable element in the page and switch to Input
 Mode.
 .TP
+.B i
+Set cursor to the last focused element in the page and switch to Input Mode.
+If no element was focused before the first element is focused like with `gi'.
+.TP
 .B CTRL\-Z
 Switch Vimb into Pass-Through Mode.
 .TP
index 62a51f8..fa4c7d6 100644 (file)
@@ -56,6 +56,7 @@ static VbResult normal_clear_input(Client *c, const NormalCmdInfo *info);
 static VbResult normal_descent(Client *c, const NormalCmdInfo *info);
 static VbResult normal_ex(Client *c, const NormalCmdInfo *info);
 static VbResult normal_fire(Client *c, const NormalCmdInfo *info);
+static VbResult normal_focus_last_active(Client *c, const NormalCmdInfo *info);
 static VbResult normal_g_cmd(Client *c, const NormalCmdInfo *info);
 static VbResult normal_hint(Client *c, const NormalCmdInfo *info);
 static VbResult normal_do_hint(Client *c, const char *prompt);
@@ -186,7 +187,7 @@ static struct {
 /* f   0x66 */ {normal_ex},
 /* g   0x67 */ {normal_g_cmd},
 /* h   0x68 */ {normal_scroll},
-/* i   0x69 */ {NULL},
+/* i   0x69 */ {normal_focus_last_active},
 /* j   0x6a */ {normal_scroll},
 /* k   0x6b */ {normal_scroll},
 /* l   0x6c */ {normal_scroll},
@@ -443,6 +444,20 @@ static VbResult normal_fire(Client *c, const NormalCmdInfo *info)
     return RESULT_ERROR;
 }
 
+static VbResult normal_focus_last_active(Client *c, const NormalCmdInfo *info)
+{
+    GVariant *variant;
+    gboolean focused;
+
+    variant = ext_proxy_eval_script_sync(c, "vimb_input_mode_element.focus();");
+    g_variant_get(variant, "(bs)", &focused);
+    if (!focused) {
+        ext_proxy_focus_input(c);
+    }
+
+    return RESULT_ERROR;
+}
+
 static VbResult normal_g_cmd(Client *c, const NormalCmdInfo *info)
 {
     Arg a;