diff --git a/src/FileListPage.cxx b/src/FileListPage.cxx index febc2cd1..bbb90379 100644 --- a/src/FileListPage.cxx +++ b/src/FileListPage.cxx @@ -389,8 +389,7 @@ FileListPage::OnCommand(struct mpdclient &c, Command cmd) CoStart(screen.find_support.Find(lw, *this, cmd)); return true; case Command::LIST_JUMP: - screen.find_support.Jump(lw, *this, *this); - SchedulePaint(); + CoStart(screen.find_support.Jump(lw, *this, *this)); return true; default: diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx index f16f7167..9deb21b8 100644 --- a/src/QueuePage.cxx +++ b/src/QueuePage.cxx @@ -556,9 +556,7 @@ QueuePage::OnCommand(struct mpdclient &c, Command cmd) CoStart(screen.find_support.Find(lw, *this, cmd)); return true; case Command::LIST_JUMP: - screen.find_support.Jump(lw, *this, *this); - SaveSelection(); - SchedulePaint(); + CoStart(screen.find_support.Jump(lw, *this, *this)); return true; default: diff --git a/src/TagListPage.cxx b/src/TagListPage.cxx index 9fb3cab8..6761ef7e 100644 --- a/src/TagListPage.cxx +++ b/src/TagListPage.cxx @@ -244,8 +244,7 @@ TagListPage::OnCommand(struct mpdclient &c, Command cmd) return true; case Command::LIST_JUMP: - find_support.Jump(lw, *this, *this); - SchedulePaint(); + CoStart(find_support.Jump(lw, *this, *this)); return true; default: diff --git a/src/page/FindSupport.cxx b/src/page/FindSupport.cxx index d377272e..a7b02e3d 100644 --- a/src/page/FindSupport.cxx +++ b/src/page/FindSupport.cxx @@ -3,21 +3,14 @@ #include "FindSupport.hxx" #include "screen.hxx" -#include "screen_utils.hxx" #include "screen_status.hxx" -#include "screen.hxx" -#include "AsyncUserInput.hxx" #include "i18n.h" #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" -#include "util/LocaleString.hxx" - -#include #define FIND_PROMPT _("Find") #define RFIND_PROMPT _("Find backward") @@ -76,48 +69,22 @@ FindSupport::Find(ListWindow &lw, const ListText &text, Command cmd) noexcept } } -void +Co::InvokeTask FindSupport::Jump(ListWindow &lw, const ListText &text, const ListRenderer &renderer) noexcept { - constexpr size_t WRLN_MAX_LINE_SIZE = 1024; - int key = 65; - - char buffer[WRLN_MAX_LINE_SIZE]; + TextInputDialog dialog{ + screen, + JUMP_PROMPT, + }; - /* In last is the whole string which is displayed in the status_window - * and search_str is the string the user entered (without the prompt) */ - char *search_str = buffer + snprintf(buffer, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT); - char *iter = search_str; + dialog.SetFragile(); - while(1) { - key = screen_getch(screen, buffer); - /* if backspace or delete was pressed, process instead of ending loop */ - if (IsBackspace(key) || key == KEY_DC) { - const char *prev = PrevCharMB(buffer, iter); - if (search_str <= prev) - iter = const_cast(prev); - *iter = '\0'; - continue; - } - /* if a control key was pressed, end loop */ - else if (iscntrl(key) || key == KEY_NPAGE || key == KEY_PPAGE) { - break; - } - else if (iter < buffer + WRLN_MAX_LINE_SIZE - 3) { - *iter++ = key; - *iter = '\0'; - } - lw.Jump(text, search_str); - - /* repaint the list_window */ + dialog.SetModifiedCallback([&lw, &text, &renderer](std::string_view value) noexcept { + lw.Jump(text, value); lw.Paint(renderer); - lw.Refresh(); - } - - last = search_str; + }); - /* ncmpc should get the command */ - keyboard_unread(key); + co_await dialog; } diff --git a/src/page/FindSupport.hxx b/src/page/FindSupport.hxx index ca201f93..40d3d931 100644 --- a/src/page/FindSupport.hxx +++ b/src/page/FindSupport.hxx @@ -38,7 +38,8 @@ public: /* query user for a string and jump to the entry * which begins with this string while the users types */ - void Jump(ListWindow &lw, const ListText &text, const ListRenderer &renderer) noexcept; + [[nodiscard]] + Co::InvokeTask Jump(ListWindow &lw, const ListText &text, const ListRenderer &renderer) noexcept; private: [[nodiscard]]