]> git.neil.brown.name Git - edlib.git/commitdiff
input: Add Keystroke-sequence interface
authorNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 05:35:51 +0000 (15:35 +1000)
committerNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 05:35:51 +0000 (15:35 +1000)
Rather than having two copies for code to convert a string (from a
menu selection) to a sequence of keystrokes, put the code in lib-input.

As the keys are space-separated, allow :SPC to be used for a space "- ".

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
lib-input.c
lib-menubar.c
mode-emacs.c

index 698954d248ad048463c06f4497d50c3d50bfe947..ecdcd66c984689e29ba34e0ea27bf035ec40661e 100644 (file)
@@ -824,6 +824,7 @@ Module features
 
 ### lib-menu
 
+- [ ] remove that blank line at the end of menus
 - [X] Enable lib-menu to show short-cut keys
 - [X] menu-bar to which we can add menus from which commands are sent
 - [ ] track movement so entry under cursor can be highlighted
index 7cf9455385a4f956b916ca062609bf3cf162b7e9..49670772629ffb246b43d9e026caaad8648ae090 100644 (file)
@@ -161,6 +161,7 @@ static const char *safe ctrl_map[][2] = {
        { ":A:LF",      ":A:C-J" },
        { ":A:Tab",     ":A:C-I" },
        { ":A:Del",     ":A:C-?" },
+       { ":SPC",       "- " },
 };
 
 static const char *map_key(const char *key safe)
@@ -227,6 +228,35 @@ DEF_CMD(keystroke)
        return Efallthrough;
 }
 
+DEF_CMD(keystroke_sequence)
+{
+       struct pane *home = ci->home;
+       const char *c = ci->str;
+       const char *e, *dash;
+       int ret;
+
+       if (!c)
+               return Enoarg;
+       while ((e = strchr(c, ' ')) != NULL) {
+               dash = "";
+               if (*c != ':' || e == c+1)
+                       dash = "-";
+               ret = call("Keystroke", home, 0, NULL,
+                          strconcat(home, dash,
+                                    strnsave(home, c, e - c)));
+               if (ret < 0)
+                       return Efail;
+               c = e+1;
+       }
+       dash = "";
+       if (*c != ':' || c[1] == '\0')
+               dash = "-";
+       ret = call("Keystroke", home, 0, NULL, strconcat(home, dash, c));
+       if (ret < 0)
+               return Efail;
+       return 1;
+}
+
 static int tspec_diff_ms(struct timespec *a safe, struct timespec *b safe)
 {
        return ((a->tv_sec - b->tv_sec) * 1000 +
@@ -465,6 +495,7 @@ static void register_map(void)
                return;
        im_map = key_alloc();
        key_add(im_map, "Keystroke", &keystroke);
+       key_add(im_map, "Keystroke-sequence", &keystroke_sequence);
        key_add(im_map, "Mouse-event", &mouse_event);
        key_add(im_map, "Mouse-grab", &mouse_grab);
        key_add(im_map, "Mode:set-mode", &set_mode);
index ad72d55fe4a4208b7e18670ff5d833027cb55ff2..6af799d04df0a6f5891fbd8bae81e61e06ab9ff0 100644 (file)
@@ -283,33 +283,11 @@ DEF_CMD(menubar_done)
 {
        struct pane *home = ci->home;
        struct mbinfo *mbi = home->data;
-       char *dash;
-       const char *c, *e;
 
        if (mbi->child)
                pane_focus(mbi->child);
-       if (!ci->str)
-               /* Abort ?? */
-               return 1;
-       c = ci->str;
-       while ((e = strchr(c, ' ')) != NULL) {
-               int ret;
-
-               dash = "";
-               if (*c != ':' || e == c+1)
-                       dash = "-";
-               ret = call("Keystroke", home, 0, NULL,
-                          strconcat(home, dash,
-                                    strnsave(home, c, e - c)));
-               if (ret < 0)
-                       return Efail;
-               c = e+1;
-       }
-       dash = "";
-       if (*c != ':' || c[1] == '\0')
-               dash = "-";
-       return call("Keystroke", home, 0, NULL,
-                   strconcat(home, dash, c));
+       call("Keystroke-sequence", home, 0, NULL, ci->str);
+       return 1;
 }
 
 DEF_CMD(menubar_root)
index 119ff35abd78f379187d7bc9bef845cbdf3753cd..d344fda32460560436580ccc18204d1baff724a3 100644 (file)
@@ -2389,8 +2389,6 @@ DEF_CMD(emacs_selection_menu)
 DEF_CMD(emacs_selection_menu_action)
 {
        struct pane *home = ci->home;
-       char *dash;
-       const char *e;
        const char *c = ci->str;
 
        if (!c)
@@ -2401,23 +2399,7 @@ DEF_CMD(emacs_selection_menu_action)
                return 1;
        }
 
-       while ((e = strchr(c, ' ')) != NULL) {
-               int ret;
-
-               dash = "";
-               if (*c != ':' || e == c+1)
-                       dash = "-";
-               ret = call("Keystroke", home, 0, NULL,
-                          strconcat(home, dash,
-                                    strnsave(home, c, e - c)));
-               if (ret < 0)
-                       return Efail;
-               c = e+1;
-       }
-       dash = "";
-       if (*c != ':' || c[1] == '\0')
-               dash = "-";
-       call("Keystroke", home, 0, NULL, strconcat(home, dash, c));
+       call("Keystroke-sequence", home, 0, NULL, c);
        return 1;
 }