diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-14 20:49:32 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-17 18:52:30 +0100 |
commit | 313b40235ac5f4a5bef4e27a9d2b8331e6b0c8ac (patch) | |
tree | 190d0e9a415aebc4df6e7d7afa5e6a47783429e5 /src/gui/gui-key.c | |
parent | fe6b69c41c45d9c9ea1a1e8b30680edf041e6022 (diff) | |
download | weechat-313b40235ac5f4a5bef4e27a9d2b8331e6b0c8ac.zip |
core: fix search of commands with raw code and alias matching
When raw code and alias for a key are both matching, the raw code must always
have higher priority.
This commit fixes this behavior and gives priority to raw code.
Diffstat (limited to 'src/gui/gui-key.c')
-rw-r--r-- | src/gui/gui-key.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 59ca20ec0..0e974bdbd 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -1608,13 +1608,16 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context, const char **chunks2, int chunks2_count, int *exact_match) { - struct t_gui_key *ptr_key; - int rc; + struct t_gui_key *ptr_key, *key1_found, *key2_found; + int rc, rc1, rc2; if ((!chunks1 && !chunks2) || !exact_match) return NULL; - *exact_match = 0; + key1_found = NULL; + key2_found = NULL; + rc1 = 0; + rc2 = 0; for (ptr_key = (buffer) ? buffer->keys : gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key) @@ -1629,11 +1632,13 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context, chunks1_count, (const char **)ptr_key->chunks, ptr_key->chunks_count); - if (rc > 0) + if (rc > rc1) { + rc1 = rc; + key1_found = ptr_key; + /* exit immediately if raw key is an exact match */ if (rc == 2) - *exact_match = 1; - break; + break; } } if (chunks2) @@ -1642,17 +1647,23 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context, chunks2_count, (const char **)ptr_key->chunks, ptr_key->chunks_count); - if (rc > 0) + if (rc > rc2) { - if (rc == 2) - *exact_match = 1; - break; + rc2 = rc; + key2_found = ptr_key; } } } } - return ptr_key; + if (key1_found) + { + *exact_match = (rc1 == 2) ? 1 : 0; + return key1_found; + } + + *exact_match = (rc2 == 2) ? 1 : 0; + return key2_found; } /* |