diff --git a/src/dialogs/TextInputDialog.cxx b/src/dialogs/TextInputDialog.cxx index c548405e..687a4bc3 100644 --- a/src/dialogs/TextInputDialog.cxx +++ b/src/dialogs/TextInputDialog.cxx @@ -223,6 +223,15 @@ TextInputDialog::OnKey(const Window window, int key) if (IsFKey(key)) return false; + if (IsBackspace(key)) { + if (cursor > 0) { /* - 1 from buf[n+1] to buf */ + MoveCursorLeft(); + DeleteChar(); + } + + return true; + } + switch (key) { case KEY_TAB: #ifndef NCMPC_MINI @@ -287,14 +296,6 @@ TextInputDialog::OnKey(const Window window, int key) DeleteChar(); } break; - case KEY_BACKSPACE3: - case KEY_BACKSPACE2: /* handle backspace: copy all */ - case KEY_BACKSPACE: /* chars starting from curpos */ - if (cursor > 0) { /* - 1 from buf[n+1] to buf */ - MoveCursorLeft(); - DeleteChar(); - } - break; case KEY_DC: /* handle delete key. As above */ case KEY_CTL('D'): if (cursor < value.length()) diff --git a/src/page/FindSupport.cxx b/src/page/FindSupport.cxx index 04523530..d377272e 100644 --- a/src/page/FindSupport.cxx +++ b/src/page/FindSupport.cxx @@ -11,6 +11,7 @@ #include "Command.hxx" #include "dialogs/TextInputDialog.hxx" #include "ui/Bell.hxx" +#include "ui/Keys.hxx" #include "ui/ListWindow.hxx" #include "ui/Options.hxx" #include "co/InvokeTask.hxx" @@ -93,7 +94,7 @@ FindSupport::Jump(ListWindow &lw, while(1) { key = screen_getch(screen, buffer); /* if backspace or delete was pressed, process instead of ending loop */ - if (key == KEY_BACKSPACE || key == KEY_DC) { + if (IsBackspace(key) || key == KEY_DC) { const char *prev = PrevCharMB(buffer, iter); if (search_str <= prev) iter = const_cast(prev); diff --git a/src/ui/Keys.hxx b/src/ui/Keys.hxx index 57b11688..caaa7555 100644 --- a/src/ui/Keys.hxx +++ b/src/ui/Keys.hxx @@ -21,3 +21,11 @@ IsFKey(int key) noexcept { return key >= KEY_F(0) && key <= KEY_F(63); } + +constexpr bool +IsBackspace(int key) noexcept +{ + return key == KEY_BACKSPACE || + key == KEY_BACKSPACE2 || + key == KEY_BACKSPACE3; +}