Code

screen_find.c: fix backspace bug
[ncmpc.git] / src / screen_find.c
index e58a1a2ad88ce869d6f12a0b43ef9a028e88580f..890f58cf14579dcf0436ec8012fa7f41437488e0 100644 (file)
@@ -96,7 +96,7 @@ screen_jump(struct list_window *lw,
            list_window_paint_callback_t paint_callback,
                void *callback_data)
 {
-       char *search_str, *iter;
+       char *search_str, *iter, *temp;
        const int WRLN_MAX_LINE_SIZE = 1024;
        int key = 65;
        command_t cmd;
@@ -111,20 +111,21 @@ screen_jump(struct list_window *lw,
        search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
        iter = search_str;
 
-       /* unfortunately wgetch returns "next/previous-page" not as an ascii-char */
-       while(!g_ascii_iscntrl(key) && key != KEY_NPAGE && key != KEY_PPAGE) {
+       while(1) {
                key = screen_getch(screen.findbuf);
-               /* if backspace or delete was pressed */
-               if (key == KEY_BACKSPACE || key == 330) {
+               /* if backspace or delete was pressed, process instead of ending loop */
+               if (key == KEY_BACKSPACE || key == KEY_DC) {
                        int i;
-                       /* don't end the loop */
-                       key = 65;
                        if (search_str <= g_utf8_find_prev_char(screen.findbuf, iter))
                                iter = g_utf8_find_prev_char(screen.findbuf, iter);
                        for (i = 0; *(iter + i) != '\0'; i++)
                                *(iter + i) = '\0';
                        continue;
                }
+               /* if a control key was pressed, end loop */
+               else if (g_ascii_iscntrl(key) || key == KEY_NPAGE || key == KEY_PPAGE) {
+                       break;
+               }
                else {
                        *iter = key;
                        if (iter < screen.findbuf + WRLN_MAX_LINE_SIZE - 3)
@@ -144,4 +145,8 @@ screen_jump(struct list_window *lw,
        ungetch(key);
        if ((cmd=get_keyboard_command()) != CMD_NONE)
                do_input_event(cmd);
+
+       temp = g_strdup(search_str);
+       g_free(screen.findbuf);
+       screen.findbuf = temp;
 }