Commit ce045134 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

make do_prev_word() work with multibyte strings, and update various

comments in do_next_word() and do_prev_word()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2273 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 97 additions and 19 deletions
+97 -19
...@@ -104,8 +104,8 @@ CVS code - ...@@ -104,8 +104,8 @@ CVS code -
move_mbleft() and moved to chars.c), move_right() (renamed move_mbleft() and moved to chars.c), move_right() (renamed
move_mbright() and moved to chars.c), do_home(), move_mbright() and moved to chars.c), do_home(),
do_verbatim_input(), do_delete(), do_tab(), do_next_word(), do_verbatim_input(), do_delete(), do_tab(), do_next_word(),
do_input(), do_output(), get_buffer(), unget_input(), do_prev_word(), do_input(), do_output(), get_buffer(),
unget_kbinput(), get_input(), parse_kbinput(), unget_input(), unget_kbinput(), get_input(), parse_kbinput(),
unparse_kbinput(), parse_verbatim_kbinput(), unparse_kbinput(), parse_verbatim_kbinput(),
do_statusbar_input(), do_statusbar_home(), do_statusbar_input(), do_statusbar_home(),
do_statusbar_verbatim_kbinput(), do_statusbar_output(), and do_statusbar_verbatim_kbinput(), do_statusbar_output(), and
......
...@@ -1325,7 +1325,8 @@ void do_next_word(void) ...@@ -1325,7 +1325,8 @@ void do_next_word(void)
assert(current != NULL && current->data != NULL); assert(current != NULL && current->data != NULL);
/* Skip letters in this word first. */ /* Move forward until we find the character after the last letter of
* the current word. */
while (current->data[current_x] != '\0') { while (current->data[current_x] != '\0') {
char_mb_len = parse_mbchar(current->data + current_x, char_mb_len = parse_mbchar(current->data + current_x,
char_mb char_mb
...@@ -1334,13 +1335,15 @@ void do_next_word(void) ...@@ -1334,13 +1335,15 @@ void do_next_word(void)
#endif #endif
, NULL); , NULL);
/* If we've found it, stop moving forward through the current
* line. */
if (!is_alnum_mbchar(char_mb)) if (!is_alnum_mbchar(char_mb))
break; break;
current_x += char_mb_len; current_x += char_mb_len;
} }
/* Go until we find the first letter of the next word. */ /* Move forward until we find the first letter of the next word. */
for (; current != NULL; current = current->next) { for (; current != NULL; current = current->next) {
while (current->data[current_x] != '\0') { while (current->data[current_x] != '\0') {
char_mb_len = parse_mbchar(current->data + current_x, char_mb_len = parse_mbchar(current->data + current_x,
...@@ -1350,12 +1353,16 @@ void do_next_word(void) ...@@ -1350,12 +1353,16 @@ void do_next_word(void)
#endif #endif
, NULL); , NULL);
/* If we've found it, stop moving forward through the
* current line. */
if (is_alnum_mbchar(char_mb)) if (is_alnum_mbchar(char_mb))
break; break;
current_x += char_mb_len; current_x += char_mb_len;
} }
/* If we've found it, stop moving forward to the beginnings of
* subsequent lines. */
if (current->data[current_x] != '\0') if (current->data[current_x] != '\0')
break; break;
...@@ -1364,6 +1371,8 @@ void do_next_word(void) ...@@ -1364,6 +1371,8 @@ void do_next_word(void)
free(char_mb); free(char_mb);
/* If we haven't found it, leave the cursor at the end of the
* file. */
if (current == NULL) if (current == NULL)
current = filebot; current = filebot;
...@@ -1378,37 +1387,106 @@ void do_prev_word(void) ...@@ -1378,37 +1387,106 @@ void do_prev_word(void)
{ {
size_t pww_save = placewewant; size_t pww_save = placewewant;
const filestruct *current_save = current; const filestruct *current_save = current;
char *char_mb = charalloc(mb_cur_max());
int char_mb_len;
bool begin_line = FALSE;
assert(current != NULL && current->data != NULL); assert(current != NULL && current->data != NULL);
current_x++; /* Move backward until we find the character before the first letter
* of the current word. */
while (!begin_line) {
char_mb_len = parse_mbchar(current->data + current_x,
char_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
/* If we've found it, stop moving backward through the current
* line. */
if (!is_alnum_mbchar(char_mb))
break;
/* Skip letters in this word first. */ if (current_x == 0)
while (current_x > 0 && isalnum(current->data[current_x - 1])) begin_line = TRUE;
current_x--; else
current_x = move_mbleft(current->data, current_x);
}
/* Go until we find the first letter of the previous word. */ /* Move backward until we find the last letter of the previous
* word. */
for (; current != NULL; current = current->prev) { for (; current != NULL; current = current->prev) {
while (current_x > 0 && !isalnum(current->data[current_x - 1])) while (!begin_line) {
current_x--; char_mb_len = parse_mbchar(current->data + current_x,
char_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
/* If we've found it, stop moving backward through the
* current line. */
if (is_alnum_mbchar(char_mb))
break;
if (current_x > 0) if (current_x == 0)
begin_line = TRUE;
else
current_x = move_mbleft(current->data, current_x);
}
/* If we've found it, stop moving backward to the ends of
* previous lines. */
if (!begin_line)
break; break;
if (current->prev != NULL) if (current->prev != NULL) {
current_x = strlen(current->prev->data) + 1; begin_line = FALSE;
current_x = strlen(current->prev->data);
}
} }
current_x--; /* If we haven't found it, leave the cursor at the beginning of the
* file. */
if (current == NULL) { if (current == NULL) {
current = fileage; current = fileage;
current_x = 0; current_x = 0;
} else { /* If we've found it, move backward until we find the character
while (current_x > 0 && isalnum(current->data[current_x - 1])) * before the first letter of the previous word. */
current_x--; } else if (!begin_line) {
if (current_x == 0)
begin_line = TRUE;
else
current_x = move_mbleft(current->data, current_x);
while (!begin_line) {
char_mb_len = parse_mbchar(current->data + current_x,
char_mb
#ifdef NANO_WIDE
, NULL
#endif
, NULL);
/* If we've found it, stop moving backward through the
* current line. */
if (!is_alnum_mbchar(char_mb))
break;
if (current_x == 0)
begin_line = TRUE;
else
current_x = move_mbleft(current->data, current_x);
}
/* If we've found it, move forward to the first letter of the
* previous word. */
if (!begin_line)
current_x += char_mb_len;
} }
free(char_mb);
placewewant = xplustabs(); placewewant = xplustabs();
/* Update the screen. */ /* Update the screen. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment