From 6376fcf552647b47543114a21b1842c3283da0ec Mon Sep 17 00:00:00 2001 From: Matt Portas Date: Thu, 28 Jan 2010 20:38:21 +0100 Subject: [PATCH] screen_find: fix garbage control chars in search string Went a control key was pressed it would exit, but still append some garbage to the end of the search string. This meant that the find next/previous command didn't work. This patch moves the loop condition to after getting the key input. --- src/screen_find.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/screen_find.c b/src/screen_find.c index e58a1a2..0d9d51f 100644 --- a/src/screen_find.c +++ b/src/screen_find.c @@ -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 == 127 || key == 330) { 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) -- 2.30.2