From 86b868601017c16288bb4cb3306f51fcfe9e47b4 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 23 Apr 2014 20:03:24 +0000 Subject: [PATCH] Returning the first shortcut that matches a given func in a given menu. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4811 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/global.c | 39 ++++----------------------------------- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 471148f5..79213cd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,11 @@ also when the PrevPage and NextPage functions are bound to meta-key sequences -- searching for these will not find them. So, instead put in the standard key code. This fixes Savannah bug #42140. + * src/global.c (first_sc_for): Stop the whole charade of preferring + control keys over meta keys over function keys, but return the first + one in the list -- just like the function name implies. This will + make a user-defined shortcut appear in the two bottomlines without + having to unbind the existing one first -- better feedback. 2014-04-22 Benno Schulenberg * src/global.c (shortcut_init): Put the movement keys in the diff --git a/src/global.c b/src/global.c index f7898e86..7493895d 100644 --- a/src/global.c +++ b/src/global.c @@ -310,46 +310,15 @@ void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *h #endif } +/* Return the first shortcut in the list of shortcuts that + * matches the given func in the given menu. */ const sc *first_sc_for(int menu, void (*func)(void)) { const sc *s; - const sc *fkeysc = NULL; - const sc *metasc = NULL; - const sc *rawsc = NULL; - for (s = sclist; s != NULL; s = s->next) { - if ((s->menu & menu) && s->scfunc == func) { - /* Memorize the first meta sequence, first function key, - * and first dedicated key. The latter is needed to be - * able to show something when the user has rebound all - * other sequences for a specific func. */ - if (s->type == META) { - if (!metasc) - metasc = s; - continue; - } else if (s->type == FKEY) { - if (!fkeysc) - fkeysc = s; - continue; - } else if (s->type == RAWINPUT) { - if (!rawsc) - rawsc = s; - continue; - } - - /* Otherwise, it was something else, so use it. */ + for (s = sclist; s != NULL; s = s->next) + if ((s->menu & menu) && s->scfunc == func) return s; - } - } - - /* If we did not find any control sequence, then prefer a - * meta sequence over a function key over a dedicated key. */ - if (metasc) - return metasc; - else if (fkeysc) - return fkeysc; - else if (rawsc) - return rawsc; #ifdef DEBUG fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long) func, menu); -- 2.39.5