From: Benno Schulenberg Date: Tue, 26 Jan 2016 10:10:20 +0000 (+0000) Subject: Jumping to the start of the current word, not to that of the preceding one. X-Git-Tag: v2.5.2~41 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5688c160a914bc849f2bcf1042c5458e3c802fae;p=nano.git Jumping to the start of the current word, not to that of the preceding one. This fixes Savannah bug #46970. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5594 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 567dba1b..d47bd6e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/files.c (update_poshistory): Do not add directories to the list of file positions. This fixes Savannah bug #46971. * src/*.c: Adjust some indentation and some line wrapping. + * src/prompt.c (do_statusbar_prev_word): When in the middle of a + word, jump to the start of the current word, not to the start of + the preceding one. This fixes Savannah bug #46970. 2016-01-25 Benno Schulenberg * src/files.c (update_poshistory): Handle an update of the first diff --git a/src/prompt.c b/src/prompt.c index bc7c43c8..e187e6c0 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -472,81 +472,26 @@ void do_statusbar_next_word(void) /* Move to the previous word in the prompt text. */ void do_statusbar_prev_word(void) { - char *char_mb; - int char_mb_len; - bool begin_line = FALSE; + bool seen_a_word = FALSE, step_forward = FALSE; assert(answer != NULL); - char_mb = charalloc(mb_cur_max()); - - /* Move backward until we find the character before the first letter - * of the current word. */ - while (!begin_line) { - char_mb_len = parse_mbchar(answer + statusbar_x, char_mb, NULL); - - /* If we've found it, stop moving backward through the current - * line. */ - if (!is_word_mbchar(char_mb, FALSE)) - break; - - if (statusbar_x == 0) - begin_line = TRUE; - else - statusbar_x = move_mbleft(answer, statusbar_x); - } - - /* Move backward until we find the last letter of the previous - * word. */ - if (statusbar_x == 0) - begin_line = TRUE; - else + /* Move backward until we pass over the start of a word. */ + while (statusbar_x != 0) { statusbar_x = move_mbleft(answer, statusbar_x); - while (!begin_line) { - char_mb_len = parse_mbchar(answer + statusbar_x, char_mb, NULL); - - /* If we've found it, stop moving backward through the current - * line. */ - if (is_word_mbchar(char_mb, FALSE)) + if (is_word_mbchar(answer + statusbar_x, FALSE)) + seen_a_word = TRUE; + else if (seen_a_word) { + /* This is space now: we've overshot the start of the word. */ + step_forward = TRUE; break; - - if (statusbar_x == 0) - begin_line = TRUE; - else - statusbar_x = move_mbleft(answer, statusbar_x); - } - - /* If we've found it, move backward until we find the character - * before the first letter of the previous word. */ - if (!begin_line) { - if (statusbar_x == 0) - begin_line = TRUE; - else - statusbar_x = move_mbleft(answer, statusbar_x); - - while (!begin_line) { - char_mb_len = parse_mbchar(answer + statusbar_x, char_mb, - NULL); - - /* If we've found it, stop moving backward through the - * current line. */ - if (!is_word_mbchar(char_mb, FALSE)) - break; - - if (statusbar_x == 0) - begin_line = TRUE; - else - statusbar_x = move_mbleft(answer, statusbar_x); } - - /* If we've found it, move forward to the first letter of the - * previous word. */ - if (!begin_line) - statusbar_x += char_mb_len; } - free(char_mb); + if (step_forward) + /* Move one character forward again to sit on the start of the word. */ + statusbar_x = move_mbright(answer, statusbar_x); update_the_bar(); }