From ea6be2f71cee2fa8bf8584a5fc342c1dabe9aca8 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 29 Sep 2023 16:16:14 +1000 Subject: [PATCH] input: Report unrecognised key sequence If keystroke is not recognised, report the fact. This helps e.g. if keyboard in is some other-language mode. Signed-off-by: NeilBrown --- DOC/TODO.md | 2 +- lib-input.c | 22 ++++++++++++++++++++-- lib-menubar.c | 3 ++- mode-emacs.c | 38 +++++++++++++++++++------------------- tests.d/01-hex | 4 ++-- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index d6cd3080..8bd04468 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -9,7 +9,7 @@ the file. ### Triage -- [ ] unknown keysequence should be reported so e.g. if keyboard +- [X] unknown keysequence should be reported so e.g. if keyboard is is Greek mode, then I will be told that Cx-b doesn't work - [ ] menubar doesn't redraw background when resized wider. - [X] open second x11 window, use selections. Close it. command diff --git a/lib-input.c b/lib-input.c index f862370c..017ec89e 100644 --- a/lib-input.c +++ b/lib-input.c @@ -225,8 +225,13 @@ DEF_CMD(keystroke) } time_ends(ci->home); if (ret <= Efail) - call("Message:default", ci->focus, 0, NULL, - "** Command Failed **"); + call("Message:default", p, 0, NULL, + strconcat(ci->home, "** Command ", key, " Failed **")); + else if (ret == Efallthrough) { + key = strconcat(ci->home, "K", mode, ci->str); + call("Message:modal", p, 0, NULL, + strconcat(ci->home, "** Command ", key, " not known **")); + } return Efallthrough; } @@ -250,6 +255,8 @@ DEF_CMD(keystroke_sequence) return Efail; c = e+1; } + if (!*c) + return 1; dash = ""; if (*c != ':' || c[1] == '\0') dash = "-"; @@ -452,6 +459,14 @@ DEF_CMD(mouse_grab) return 1; } +DEF_CMD(input_cancel) +{ + /* Other handlers fall-through. We catch so that + * it doesn't appear to be ignored + */ + return 1; +} + DEF_CMD(refocus) { struct input_mode *im = ci->home->data; @@ -509,6 +524,9 @@ static void register_map(void) key_add(im_map, "Notify:Close", &close_focus); key_add(im_map, "input:log", &log_input); key_add(im_map, "Close", &input_close); + + key_add(im_map, "Cancel", &input_cancel); + key_add(im_map, "Abort", &input_cancel); } DEF_LOOKUP_CMD(input_handle, im_map); diff --git a/lib-menubar.c b/lib-menubar.c index b4a26550..5ad0d456 100644 --- a/lib-menubar.c +++ b/lib-menubar.c @@ -287,7 +287,8 @@ DEF_CMD(menubar_done) if (mbi->child) pane_take_focus(mbi->child); - call("Keystroke-sequence", home, 0, NULL, ci->str); + if (ci->str && ci->str[0]) + call("Keystroke-sequence", home, 0, NULL, ci->str); return 1; } diff --git a/mode-emacs.c b/mode-emacs.c index 07e2647b..cd287e56 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -215,7 +215,7 @@ REDEF_CMD(emacs_move) ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), ci->mark, NULL, mv->extra); - if (ret <= 0) + if (ret < 0) return ret; if (strcmp(mv->type, "Move-View") == 0) @@ -226,13 +226,13 @@ REDEF_CMD(emacs_move) /* Discard a transient selection */ clear_selection(ci->focus, NULL, mk, 2); - return ret; + return 1; } REDEF_CMD(emacs_delete) { struct move_command *mv = container_of(ci->comm, struct move_command, cmd); - int ret = 0; + int ret; struct mark *m, *mk; if (!ci->mark) @@ -250,7 +250,7 @@ REDEF_CMD(emacs_delete) ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), m); - if (ret <= 0) { + if (ret < 0) { mark_free(m); return ret; } @@ -261,14 +261,14 @@ REDEF_CMD(emacs_delete) mark_free(m); call("Mode:set-num2", ci->focus, N2_undo_delete); - return ret; + return 1; } REDEF_CMD(emacs_kill) { /* Like delete, but copy to copy-buffer */ struct move_command *mv = container_of(ci->comm, struct move_command, cmd); - int ret = 0; + int ret; struct mark *m; char *str; @@ -284,7 +284,7 @@ REDEF_CMD(emacs_kill) else ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), m); - if (ret <= 0) { + if (ret < 0) { mark_free(m); return ret; } @@ -299,13 +299,13 @@ REDEF_CMD(emacs_kill) mark_free(m); call("Mode:set-num2", ci->focus, N2_undo_delete); - return ret; + return 1; } REDEF_CMD(emacs_case) { struct move_command *mv = container_of(ci->comm, struct move_command, cmd); - int ret = 0; + int ret; struct mark *start = NULL; int cnt = mv->direction * RPT_NUM(ci); int dir; @@ -388,7 +388,7 @@ REDEF_CMD(emacs_case) mark_to_mark(ci->mark, start); mark_free(start); } - return ret; + return 1; } REDEF_CMD(emacs_swap) @@ -399,7 +399,6 @@ REDEF_CMD(emacs_swap) * previous objects. Object is determined by mv->type. */ struct move_command *mv = container_of(ci->comm, struct move_command, cmd); - int ret = 0; struct mark *start = NULL; int cnt = mv->direction * RPT_NUM(ci); int dir; @@ -469,7 +468,7 @@ REDEF_CMD(emacs_swap) mark_to_mark(ci->mark, start); mark_free(start); } - return ret; + return 1; } DEF_CMD(emacs_move_view_other) @@ -645,7 +644,8 @@ DEF_CMD(emacs_exit) return Efail; } attr_set_str(&p->attrs, "done-key", "emacs:deactivate"); - return call("docs:show-modified", p); + call("docs:show-modified", p); + return 1; } else call("event:deactivate", ci->focus); return 1; @@ -678,7 +678,7 @@ DEF_CMD(emacs_insert) ret = call(dc, ci->focus, ci->num, ci->mark, NULL, !first); call("Mode:set-num2", ci->focus, N2_undo_insert); - return ret; + return ret < 0 ? ret : 1; } DEF_CMD(emacs_quote_insert) @@ -709,7 +709,7 @@ DEF_CMD(emacs_quote_insert) ret = call("Replace", ci->focus, 1, ci->mark, str, !first); call("Mode:set-num2", ci->focus, N2_undo_insert); - return ret; + return ret < 0 ? ret : 1; } static struct { @@ -762,7 +762,7 @@ DEF_CMD(emacs_insert_other) } /* A newline starts a new undo */ call("Mode:set-num2", ci->focus, (*ins == '\n') ? 0 : N2_undo_insert); - return ret; + return ret < 0 ? ret : 1; } DEF_CMD(emacs_interactive_insert) @@ -785,7 +785,7 @@ DEF_CMD(emacs_interactive_insert) !first); call("Mode:set-num2", ci->focus, strchr(ci->str, '\n') ? 0 : N2_undo_insert); - return ret; + return ret < 0 ? ret : 1; } DEF_CMD(emacs_interactive_delete) @@ -801,7 +801,7 @@ DEF_CMD(emacs_interactive_delete) N2(ci) == N2_undo_insert, ci->mark2); call("Mode:set-num2", ci->focus, strchr(ci->str, '\n') ? 0 : N2_undo_delete); - return ret; + return ret < 0 ? ret : 1; } DEF_CMD(emacs_undo) @@ -916,7 +916,7 @@ DEF_CMD(find_done) return 1; } ret = call("popup:close", ci->focus, 0, NULL, norm ?: str); - return ret; + return ret < 0 ? ret : 1; } struct find_helper { diff --git a/tests.d/01-hex b/tests.d/01-hex index b3204d86..d92dc8a1 100644 --- a/tests.d/01-hex +++ b/tests.d/01-hex @@ -66,7 +66,7 @@ Display 80,30 59916409B88D2F03AEF88C44A55EBF77 11,3 Key ":C-C" Display 80,30 97948AE8E3CDD3ACAF8E85B77EF95795 11,3 Key ":C-C" -Display 80,30 59916409B88D2F03AEF88C44A55EBF77 11,3 +Display 80,30 0EBDF165D3D4F22FDD70842E59F8099A 11,3 Key ":C-D" Display 80,30 F233AC0805C7B68515D774340BACB87F 11,3 Key ":C-D" @@ -83,4 +83,4 @@ Key ":C-X" Display 80,30 03B92C6B72859C64F0A8D6830B7789BC 14,3 Key ":C-C" Display 80,30 59916409B88D2F03AEF88C44A55EBF77 14,3 -Close 604 +Close 605 -- 2.39.5