commit 8766e7bdcb9c9768a4c127c3cd76e3bb6d8be8cb
parent bb4d0d548a9a95d8b9e166fc4e4ae07f5a11ec41
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 27 Jun 2017 12:34:11 +0200
tweaks: reshuffle some things to condense the code
Diffstat:
2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/src/move.c b/src/move.c
@@ -413,12 +413,12 @@ void do_end(bool be_clever)
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) {
- bool last_chunk;
+ bool last_chunk = FALSE;
size_t leftedge = get_chunk_leftedge(openfile->current, was_column);
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
- leftedge,
- &last_chunk);
+ leftedge, &last_chunk);
size_t rightedge_x;
+
/* If we're on the last chunk, we're already at the end of the line.
* Otherwise, we're one column past the end of the line. Shifting
* backwards one column might put us in the middle of a multi-column
diff --git a/src/winio.c b/src/winio.c
@@ -2766,15 +2766,14 @@ int update_softwrapped_line(filestruct *fileptr)
starting_row = row;
while (row < editwinrows) {
- bool end_of_line;
+ bool end_of_line = FALSE;
to_col = get_softwrap_breakpoint(fileptr->data, from_col, &end_of_line);
blank_row(edit, row, 0, COLS);
/* Convert the chunk to its displayable form and draw it. */
- converted = display_string(fileptr->data, from_col, to_col - from_col,
- TRUE);
+ converted = display_string(fileptr->data, from_col, to_col - from_col, TRUE);
edit_draw(fileptr, converted, row++, from_col);
free(converted);
@@ -2869,11 +2868,10 @@ int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge)
/* Advance through the requested number of chunks. */
for (i = nrows; i > 0; i--) {
if (current_leftedge < last_leftedge) {
- bool end_of_line;
+ bool dummy;
current_leftedge = get_softwrap_breakpoint((*line)->data,
- current_leftedge,
- &end_of_line);
+ current_leftedge, &dummy);
continue;
}
@@ -3011,8 +3009,6 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
int char_len = 0;
/* Length of current character, in bytes. */
- *end_of_line = FALSE;
-
while (*text != '\0' && column < leftedge)
text += parse_mbchar(text, NULL, &column);
@@ -3092,7 +3088,7 @@ size_t actual_last_column(size_t leftedge, size_t column)
size_t get_chunk(filestruct *line, size_t column, size_t *leftedge)
{
size_t current_chunk = 0, start_col = 0, end_col;
- bool end_of_line;
+ bool end_of_line = FALSE;
while (TRUE) {
end_col = get_softwrap_breakpoint(line->data, start_col, &end_of_line);
@@ -3433,6 +3429,8 @@ void spotlight(bool active, size_t from_col, size_t to_col)
char *word;
size_t word_span, room;
+ place_the_cursor(FALSE);
+
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) {
spotlight_softwrapped(active, from_col, to_col);
@@ -3440,8 +3438,6 @@ void spotlight(bool active, size_t from_col, size_t to_col)
}
#endif
- place_the_cursor(FALSE);
-
/* This is so we can show zero-length matches. */
if (to_col == from_col) {
word = mallocstrcpy(NULL, " ");
@@ -3481,16 +3477,12 @@ void spotlight(bool active, size_t from_col, size_t to_col)
* line breaks, since they're not actually part of the spotlighted text. */
void spotlight_softwrapped(bool active, size_t from_col, size_t to_col)
{
- ssize_t row;
+ ssize_t row = openfile->current_y;
size_t leftedge = get_chunk_leftedge(openfile->current, from_col);
size_t break_col;
- bool end_of_line;
+ bool end_of_line = FALSE;
char *word;
- place_the_cursor(FALSE);
-
- row = openfile->current_y;
-
while (row < editwinrows) {
break_col = get_softwrap_breakpoint(openfile->current->data,
leftedge, &end_of_line);
@@ -3523,9 +3515,7 @@ void spotlight_softwrapped(bool active, size_t from_col, size_t to_col)
if (end_of_line)
break;
- row++;
-
- wmove(edit, row, 0);
+ wmove(edit, ++row, 0);
leftedge = break_col;
from_col = break_col;