From: Benno Schulenberg Date: Sat, 5 Sep 2015 09:40:09 +0000 (+0000) Subject: Jumping to the beginning of the current word when in its middle X-Git-Tag: v2.5.0~90 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=b4103321e66533467346e2c9aa6d7fe51bafc143;p=nano.git Jumping to the beginning of the current word when in its middle instead of to the beginning of the preceding word, to match the behaviour of Pico and of most other editors. It also rewrites the entire routine. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5372 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 3bf75d4a..0edbd4ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ text this significant slowdown. This fixes Savannah bug #45684 reported by Wyatt Ward. * src/move.c (do_prev_word): Drop a return value that is never used. + * src/move.c (do_prev_word): When in the middle of a word, jump to + its beginning instead of to the beginning of the preceding word. + Nano now matches the behaviour of Pico and of most other editors. + This fixes Savannah bug #45413. 2015-09-04 Benno Schulenberg * src/chars.c: Reverting r5354 from August 12. This fixes Savannah diff --git a/src/move.c b/src/move.c index b8898002..a462cc37 100644 --- a/src/move.c +++ b/src/move.c @@ -317,107 +317,41 @@ void do_prev_word(bool allow_punct, bool allow_update) { size_t pww_save = openfile->placewewant; filestruct *current_save = openfile->current; - char *char_mb; - int char_mb_len; - bool begin_line = FALSE; + bool seen_a_word = FALSE, step_forward = FALSE; assert(openfile->current != NULL && openfile->current->data != 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(openfile->current->data + - openfile->current_x, char_mb, NULL); - - /* If we've found it, stop moving backward through the current - * line. */ - if (!is_word_mbchar(char_mb, allow_punct)) - break; - - if (openfile->current_x == 0) - begin_line = TRUE; - else - openfile->current_x = move_mbleft(openfile->current->data, - openfile->current_x); - } - - /* Move backward until we find the last letter of the previous - * word. */ - if (openfile->current_x == 0) - begin_line = TRUE; - else - openfile->current_x = move_mbleft(openfile->current->data, - openfile->current_x); - - for (; openfile->current != NULL; - openfile->current = openfile->current->prev) { - while (!begin_line) { - char_mb_len = parse_mbchar(openfile->current->data + - openfile->current_x, char_mb, NULL); - - /* If we've found it, stop moving backward through the - * current line. */ - if (is_word_mbchar(char_mb, allow_punct)) + /* Move backward until we pass over the start of a word. */ + while (TRUE) { + /* If at the head of a line, move to the end of the preceding one. */ + if (openfile->current_x == 0) { + if (openfile->current->prev == NULL) break; - - if (openfile->current_x == 0) - begin_line = TRUE; - else - openfile->current_x = - move_mbleft(openfile->current->data, - openfile->current_x); - } - - /* If we've found it, stop moving backward to the ends of - * previous lines. */ - if (!begin_line) - break; - - if (openfile->current != openfile->fileage) { - begin_line = FALSE; - openfile->current_x = strlen(openfile->current->prev->data); + openfile->current = openfile->current->prev; + openfile->current_x = strlen(openfile->current->data); } - } - - /* If we haven't found it, move to the beginning of the file. */ - if (openfile->current == NULL) - openfile->current = openfile->fileage; - /* If we've found it, move backward until we find the character - * before the first letter of the previous word. */ - else if (!begin_line) { - if (openfile->current_x == 0) - begin_line = TRUE; - else - openfile->current_x = move_mbleft(openfile->current->data, - openfile->current_x); - - while (!begin_line) { - char_mb_len = parse_mbchar(openfile->current->data + - openfile->current_x, char_mb, NULL); - /* If we've found it, stop moving backward through the - * current line. */ - if (!is_word_mbchar(char_mb, allow_punct)) - break; + /* Step back one character. */ + openfile->current_x = move_mbleft(openfile->current->data, + openfile->current_x); + if (is_word_mbchar(openfile->current->data + openfile->current_x, + allow_punct)) { + seen_a_word = TRUE; + /* If at the head of a line now, this surely is a word start. */ if (openfile->current_x == 0) - begin_line = TRUE; - else - openfile->current_x = - move_mbleft(openfile->current->data, - openfile->current_x); + break; + } else if (seen_a_word) { + /* This is space now: we've overshot the start of the word. */ + step_forward = TRUE; + break; } - - /* If we've found it, move forward to the first letter of the - * previous word. */ - if (!begin_line) - openfile->current_x += char_mb_len; } - free(char_mb); - + if (step_forward) + /* Move one character forward again to sit on the start of the word. */ + openfile->current_x = move_mbright(openfile->current->data, + openfile->current_x); openfile->placewewant = xplustabs(); /* If allow_update is TRUE, update the screen. */