diff --git a/src/KeyName.cxx b/src/KeyName.cxx index 84b454e1..8d9b3bbd 100644 --- a/src/KeyName.cxx +++ b/src/KeyName.cxx @@ -60,11 +60,9 @@ GetKeyName(int key) noexcept { static char buf[32]; - for (int i = 0; i < 64; ++i) { - if (key == KEY_F(i)) { - snprintf(buf, sizeof(buf), "F%u", i); - return buf; - } + if (IsFKey(key)) { + snprintf(buf, sizeof(buf), "F%u", key - KEY_F0); + return buf; } const char *name = keyname(key); @@ -132,11 +130,9 @@ GetLocalizedKeyName(int key) noexcept static char buf[32]; - for (int i = 0; i <= 63; i++) { - if (key == KEY_F(i)) { - snprintf(buf, sizeof(buf), "F%d", i ); - return buf; - } + if (IsFKey(key)) { + snprintf(buf, sizeof(buf), "F%u", key - KEY_F0); + return buf; } const char *name = keyname(key); diff --git a/src/dialogs/TextInputDialog.cxx b/src/dialogs/TextInputDialog.cxx index 5eb53195..c548405e 100644 --- a/src/dialogs/TextInputDialog.cxx +++ b/src/dialogs/TextInputDialog.cxx @@ -220,11 +220,8 @@ TextInputDialog::OnKey(const Window window, int key) } /* check if key is a function key */ - for (size_t i = 0; i < 63; i++) - if (key == (int)KEY_F(i)) { - key = KEY_F(1); - i = 64; - } + if (IsFKey(key)) + return false; switch (key) { case KEY_TAB: @@ -331,7 +328,6 @@ TextInputDialog::OnKey(const Window window, int key) case KEY_IC: case KEY_PPAGE: case KEY_NPAGE: - case KEY_F(1): /* ignore char */ break; default: diff --git a/src/ui/Keys.hxx b/src/ui/Keys.hxx index 469c7cd1..57b11688 100644 --- a/src/ui/Keys.hxx +++ b/src/ui/Keys.hxx @@ -15,3 +15,9 @@ enum : int { KEY_ESCAPE = 0x1b, KEY_BACKSPACE3 = 0x7f, }; + +constexpr bool +IsFKey(int key) noexcept +{ + return key >= KEY_F(0) && key <= KEY_F(63); +}