Commit 8766e7bd authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: reshuffle some things to condense the code

No related merge requests found
Showing with 13 additions and 23 deletions
+13 -23
...@@ -413,12 +413,12 @@ void do_end(bool be_clever) ...@@ -413,12 +413,12 @@ void do_end(bool be_clever)
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
bool last_chunk; bool last_chunk = FALSE;
size_t leftedge = get_chunk_leftedge(openfile->current, was_column); size_t leftedge = get_chunk_leftedge(openfile->current, was_column);
size_t rightedge = get_softwrap_breakpoint(openfile->current->data, size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
leftedge, leftedge, &last_chunk);
&last_chunk);
size_t rightedge_x; size_t rightedge_x;
/* If we're on the last chunk, we're already at the end of the line. /* 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 * 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 * backwards one column might put us in the middle of a multi-column
......
...@@ -2766,15 +2766,14 @@ int update_softwrapped_line(filestruct *fileptr) ...@@ -2766,15 +2766,14 @@ int update_softwrapped_line(filestruct *fileptr)
starting_row = row; starting_row = row;
while (row < editwinrows) { while (row < editwinrows) {
bool end_of_line; bool end_of_line = FALSE;
to_col = get_softwrap_breakpoint(fileptr->data, from_col, &end_of_line); to_col = get_softwrap_breakpoint(fileptr->data, from_col, &end_of_line);
blank_row(edit, row, 0, COLS); blank_row(edit, row, 0, COLS);
/* Convert the chunk to its displayable form and draw it. */ /* Convert the chunk to its displayable form and draw it. */
converted = display_string(fileptr->data, from_col, to_col - from_col, converted = display_string(fileptr->data, from_col, to_col - from_col, TRUE);
TRUE);
edit_draw(fileptr, converted, row++, from_col); edit_draw(fileptr, converted, row++, from_col);
free(converted); free(converted);
...@@ -2869,11 +2868,10 @@ int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge) ...@@ -2869,11 +2868,10 @@ int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge)
/* Advance through the requested number of chunks. */ /* Advance through the requested number of chunks. */
for (i = nrows; i > 0; i--) { for (i = nrows; i > 0; i--) {
if (current_leftedge < last_leftedge) { if (current_leftedge < last_leftedge) {
bool end_of_line; bool dummy;
current_leftedge = get_softwrap_breakpoint((*line)->data, current_leftedge = get_softwrap_breakpoint((*line)->data,
current_leftedge, current_leftedge, &dummy);
&end_of_line);
continue; continue;
} }
...@@ -3011,8 +3009,6 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge, ...@@ -3011,8 +3009,6 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
int char_len = 0; int char_len = 0;
/* Length of current character, in bytes. */ /* Length of current character, in bytes. */
*end_of_line = FALSE;
while (*text != '\0' && column < leftedge) while (*text != '\0' && column < leftedge)
text += parse_mbchar(text, NULL, &column); text += parse_mbchar(text, NULL, &column);
...@@ -3092,7 +3088,7 @@ size_t actual_last_column(size_t leftedge, size_t 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 get_chunk(filestruct *line, size_t column, size_t *leftedge)
{ {
size_t current_chunk = 0, start_col = 0, end_col; size_t current_chunk = 0, start_col = 0, end_col;
bool end_of_line; bool end_of_line = FALSE;
while (TRUE) { while (TRUE) {
end_col = get_softwrap_breakpoint(line->data, start_col, &end_of_line); 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) ...@@ -3433,6 +3429,8 @@ void spotlight(bool active, size_t from_col, size_t to_col)
char *word; char *word;
size_t word_span, room; size_t word_span, room;
place_the_cursor(FALSE);
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
spotlight_softwrapped(active, from_col, to_col); spotlight_softwrapped(active, from_col, to_col);
...@@ -3440,8 +3438,6 @@ void spotlight(bool active, size_t from_col, size_t to_col) ...@@ -3440,8 +3438,6 @@ void spotlight(bool active, size_t from_col, size_t to_col)
} }
#endif #endif
place_the_cursor(FALSE);
/* This is so we can show zero-length matches. */ /* This is so we can show zero-length matches. */
if (to_col == from_col) { if (to_col == from_col) {
word = mallocstrcpy(NULL, " "); word = mallocstrcpy(NULL, " ");
...@@ -3481,16 +3477,12 @@ void spotlight(bool active, size_t from_col, size_t to_col) ...@@ -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. */ * 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) 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 leftedge = get_chunk_leftedge(openfile->current, from_col);
size_t break_col; size_t break_col;
bool end_of_line; bool end_of_line = FALSE;
char *word; char *word;
place_the_cursor(FALSE);
row = openfile->current_y;
while (row < editwinrows) { while (row < editwinrows) {
break_col = get_softwrap_breakpoint(openfile->current->data, break_col = get_softwrap_breakpoint(openfile->current->data,
leftedge, &end_of_line); leftedge, &end_of_line);
...@@ -3523,9 +3515,7 @@ void spotlight_softwrapped(bool active, size_t from_col, size_t to_col) ...@@ -3523,9 +3515,7 @@ void spotlight_softwrapped(bool active, size_t from_col, size_t to_col)
if (end_of_line) if (end_of_line)
break; break;
row++; wmove(edit, ++row, 0);
wmove(edit, row, 0);
leftedge = break_col; leftedge = break_col;
from_col = break_col; from_col = break_col;
......
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