From 285e3c4aa27f6454e87d29a8d89ab7f7452796a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 5 Apr 2021 14:33:44 +0200 Subject: [PATCH 1/3] config: parse_key_binding_section(): use provided action-map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t call has_key_binding_collisions() with ‘binding_action_map’ unconditionally; use the provided ‘action_map’ instead. This fixes wrong error messages for key combo collisions in key binding sections other than the regular “key-bindings”. --- CHANGELOG.md | 2 ++ config.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b5f9c3..970c070b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ * Crash caused by a double free originating in `XTSMGRAPHICS` - set number of color registers (https://codeberg.org/dnkl/foot/issues/427). +* Wrong action referenced in error message for key binding collisions + (https://codeberg.org/dnkl/foot/issues/432). ### Security diff --git a/config.c b/config.c index ab0236bb..0112b9e4 100644 --- a/config.c +++ b/config.c @@ -1393,7 +1393,7 @@ parse_key_binding_section( if (!parse_key_combos( conf, value, &key_combos, section, key, path, lineno) || has_key_binding_collisions( - conf, action, binding_action_map, bindings, &key_combos, + conf, action, action_map, bindings, &key_combos, path, lineno)) { free(pipe_argv); From fa6382aeb3d1daa2ee66c5581970c1b56d692339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 5 Apr 2021 14:37:42 +0200 Subject: [PATCH 2/3] doc: foot.ini: fix default value for delete-next-word --- doc/foot.ini.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index ac815b23..dcf644ef 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -593,7 +593,7 @@ scrollback search mode. The syntax is exactly the same as the regular Deletes the **character after** the cursor. Default: _Delete_. *delete-next-word* - Deletes the **word after** the cursor. Default: _Mod1+b + Deletes the **word after** the cursor. Default: _Mod1+d Control+Delete_. *extend-to-word-boundary* From 65dead29e01677d698a220ef245505708f065951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 5 Apr 2021 14:50:21 +0200 Subject: [PATCH 3/3] config: make {search,url}_binding_action_map[] function local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures we don’t accidentally reference them from places we shouldn’t. Unfortunately, binding_action_map[] (for “normal” key bindings) cannot easily be made function local since it is used when parsing both key- and mouse bindings (i.e. it’s used in multiple functions). --- config.c | 68 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/config.c b/config.c index 0112b9e4..6da5b68d 100644 --- a/config.c +++ b/config.c @@ -91,40 +91,6 @@ static const char *const binding_action_map[] = { static_assert(ALEN(binding_action_map) == BIND_ACTION_COUNT, "binding action map size mismatch"); -static const char *const search_binding_action_map[] = { - [BIND_ACTION_SEARCH_NONE] = NULL, - [BIND_ACTION_SEARCH_CANCEL] = "cancel", - [BIND_ACTION_SEARCH_COMMIT] = "commit", - [BIND_ACTION_SEARCH_FIND_PREV] = "find-prev", - [BIND_ACTION_SEARCH_FIND_NEXT] = "find-next", - [BIND_ACTION_SEARCH_EDIT_LEFT] = "cursor-left", - [BIND_ACTION_SEARCH_EDIT_LEFT_WORD] = "cursor-left-word", - [BIND_ACTION_SEARCH_EDIT_RIGHT] = "cursor-right", - [BIND_ACTION_SEARCH_EDIT_RIGHT_WORD] = "cursor-right-word", - [BIND_ACTION_SEARCH_EDIT_HOME] = "cursor-home", - [BIND_ACTION_SEARCH_EDIT_END] = "cursor-end", - [BIND_ACTION_SEARCH_DELETE_PREV] = "delete-prev", - [BIND_ACTION_SEARCH_DELETE_PREV_WORD] = "delete-prev-word", - [BIND_ACTION_SEARCH_DELETE_NEXT] = "delete-next", - [BIND_ACTION_SEARCH_DELETE_NEXT_WORD] = "delete-next-word", - [BIND_ACTION_SEARCH_EXTEND_WORD] = "extend-to-word-boundary", - [BIND_ACTION_SEARCH_EXTEND_WORD_WS] = "extend-to-next-whitespace", - [BIND_ACTION_SEARCH_CLIPBOARD_PASTE] = "clipboard-paste", - [BIND_ACTION_SEARCH_PRIMARY_PASTE] = "primary-paste", -}; - -static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT, - "search binding action map size mismatch"); - -static const char *const url_binding_action_map[] = { - [BIND_ACTION_URL_NONE] = NULL, - [BIND_ACTION_URL_CANCEL] = "cancel", - [BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL] = "toggle-url-visible", -}; - -static_assert(ALEN(url_binding_action_map) == BIND_ACTION_URL_COUNT, - "URL binding action map size mismatch"); - #define LOG_AND_NOTIFY_ERR(...) \ do { \ LOG_ERR(__VA_ARGS__); \ @@ -1462,6 +1428,31 @@ parse_section_search_bindings( const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) { + static const char *const search_binding_action_map[] = { + [BIND_ACTION_SEARCH_NONE] = NULL, + [BIND_ACTION_SEARCH_CANCEL] = "cancel", + [BIND_ACTION_SEARCH_COMMIT] = "commit", + [BIND_ACTION_SEARCH_FIND_PREV] = "find-prev", + [BIND_ACTION_SEARCH_FIND_NEXT] = "find-next", + [BIND_ACTION_SEARCH_EDIT_LEFT] = "cursor-left", + [BIND_ACTION_SEARCH_EDIT_LEFT_WORD] = "cursor-left-word", + [BIND_ACTION_SEARCH_EDIT_RIGHT] = "cursor-right", + [BIND_ACTION_SEARCH_EDIT_RIGHT_WORD] = "cursor-right-word", + [BIND_ACTION_SEARCH_EDIT_HOME] = "cursor-home", + [BIND_ACTION_SEARCH_EDIT_END] = "cursor-end", + [BIND_ACTION_SEARCH_DELETE_PREV] = "delete-prev", + [BIND_ACTION_SEARCH_DELETE_PREV_WORD] = "delete-prev-word", + [BIND_ACTION_SEARCH_DELETE_NEXT] = "delete-next", + [BIND_ACTION_SEARCH_DELETE_NEXT_WORD] = "delete-next-word", + [BIND_ACTION_SEARCH_EXTEND_WORD] = "extend-to-word-boundary", + [BIND_ACTION_SEARCH_EXTEND_WORD_WS] = "extend-to-next-whitespace", + [BIND_ACTION_SEARCH_CLIPBOARD_PASTE] = "clipboard-paste", + [BIND_ACTION_SEARCH_PRIMARY_PASTE] = "primary-paste", + }; + + static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT, + "search binding action map size mismatch"); + return parse_key_binding_section( "search-bindings", key, value, BIND_ACTION_SEARCH_COUNT, search_binding_action_map, &conf->bindings.search, conf, path, lineno); @@ -1472,6 +1463,15 @@ parse_section_url_bindings( const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) { + static const char *const url_binding_action_map[] = { + [BIND_ACTION_URL_NONE] = NULL, + [BIND_ACTION_URL_CANCEL] = "cancel", + [BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL] = "toggle-url-visible", + }; + + static_assert(ALEN(url_binding_action_map) == BIND_ACTION_URL_COUNT, + "URL binding action map size mismatch"); + return parse_key_binding_section( "url-bindings", key, value, BIND_ACTION_URL_COUNT, url_binding_action_map, &conf->bindings.url, conf, path, lineno);