From 275e61eaf2d624927376176d2561336b7bf257f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Sun, 26 Apr 2020 15:25:15 -0300 Subject: [PATCH] display: an attempt to support the scroll bar also with --softwrap Signed-off-by: Benno Schulenberg --- src/cut.c | 5 +++-- src/files.c | 5 +++-- src/nano.c | 22 +++++++++++++++------- src/nano.h | 4 ++++ src/winio.c | 13 +++++++++++-- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/cut.c b/src/cut.c index fbc145c3..4de93467 100644 --- a/src/cut.c +++ b/src/cut.c @@ -106,9 +106,10 @@ void do_deletion(undo_type action) /* If the number of screen rows that a softwrapped line occupies * has changed, we need a full refresh. */ - if (ISSET(SOFTWRAP) && refresh_needed == FALSE && - number_of_chunks_in(openfile->current) != old_amount) + if (ISSET(SOFTWRAP) && number_of_chunks_in(openfile->current) != old_amount) { + renumber_from(openfile->current); refresh_needed = TRUE; + } #endif set_modified(); diff --git a/src/files.c b/src/files.c index 343d8734..73a639d2 100644 --- a/src/files.c +++ b/src/files.c @@ -537,9 +537,10 @@ void redecorate_after_switch(void) /* While in a different buffer, the screen may have been resized * or softwrap mode maybe have been toggled, so make sure that the * starting column for the first row gets an appropriate value. */ - if (ISSET(SOFTWRAP)) + if (ISSET(SOFTWRAP)) { ensure_firstcolumn_is_aligned(); - else + renumber_from(openfile->filetop); + } else openfile->firstcolumn = 0; #endif diff --git a/src/nano.c b/src/nano.c index a30ec912..39d060e1 100644 --- a/src/nano.c +++ b/src/nano.c @@ -76,6 +76,8 @@ linestruct *make_new_node(linestruct *prevnode) #endif newnode->lineno = (prevnode) ? prevnode->lineno + 1 : 1; #ifndef NANO_TINY + newnode->chunk_nr = (prevnode) ? + prevnode->chunk_nr + number_of_chunks_in(prevnode) + 1 : 1; newnode->has_anchor = FALSE; #endif @@ -151,6 +153,7 @@ linestruct *copy_node(const linestruct *src) #endif dst->lineno = src->lineno; #ifndef NANO_TINY + dst->chunk_nr = src->chunk_nr; dst->has_anchor = FALSE; #endif @@ -188,6 +191,10 @@ void renumber_from(linestruct *line) while (line != NULL) { line->lineno = ++number; +#ifndef NANO_TINY + line->chunk_nr = (line->prev) ? + line->prev->chunk_nr + number_of_chunks_in(line->prev) + 1 : 1; +#endif line = line->next; } } @@ -1038,7 +1045,7 @@ void regenerate_screen(void) LINES = win.ws_row; #endif #ifndef NANO_TINY - thebar = (LINES > 5 && COLS > 9 && !ISSET(SOFTWRAP)) ? 1 : 0; + thebar = (LINES > 5 && COLS > 9) ? 1 : 0; bardata = nrealloc(bardata, LINES * sizeof(int)); #endif editwincols = COLS - margin - thebar; @@ -1082,12 +1089,12 @@ void do_toggle(int flag) signal_init(); break; case SOFTWRAP: - if (!ISSET(SOFTWRAP)) { - thebar = (LINES > 5 && COLS > 9) ? 1 : 0; - bardata = nrealloc(bardata, LINES * sizeof(int)); + if (ISSET(SOFTWRAP)) + renumber_from(openfile->filetop); + else openfile->firstcolumn = 0; - } else - thebar = 0; + thebar = (LINES > 5 && COLS > 9) ? 1 : 0; + bardata = nrealloc(bardata, LINES * sizeof(int)); editwincols = COLS - margin - thebar; refresh_needed = TRUE; break; @@ -1485,6 +1492,7 @@ void inject(char *burst, size_t count) if (ISSET(SOFTWRAP) && ((openfile->current_y == editwinrows - 1 && chunk_for(xplustabs(), openfile->current) > original_row) || number_of_chunks_in(openfile->current) != old_amount)) { + renumber_from(openfile->current); refresh_needed = TRUE; focusing = FALSE; } @@ -2285,7 +2293,7 @@ int main(int argc, char **argv) curs_set(0); #ifndef NANO_TINY - thebar = (LINES > 5 && COLS > 9 && !ISSET(SOFTWRAP)) ? 1 : 0; + thebar = (LINES > 5 && COLS > 9) ? 1 : 0; bardata = nrealloc(bardata, LINES * sizeof(int)); #endif editwincols = COLS - thebar; diff --git a/src/nano.h b/src/nano.h index dffabe70..768caa43 100644 --- a/src/nano.h +++ b/src/nano.h @@ -284,6 +284,10 @@ typedef struct linestruct { /* The text of this line. */ ssize_t lineno; /* The number of this line. */ +#ifndef NANO_TINY + ssize_t chunk_nr; + /* The ordinal number of the first chunk in this line. */ +#endif struct linestruct *next; /* Next node. */ struct linestruct *prev; diff --git a/src/winio.c b/src/winio.c index 04010fe4..fbc4f9c1 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2412,7 +2412,7 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) if (is_shorter || ISSET(SOFTWRAP)) wclrtoeol(edit); - if (is_shorter && thebar) + if (thebar) mvwaddch(edit, row, COLS - 1, bardata[row]); #ifdef USING_OLD_NCURSES @@ -2968,7 +2968,16 @@ bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge) void draw_scrollbar(void) { int totalrows = openfile->filebot->lineno; - int lowest = ((openfile->edittop->lineno - 1) * editwinrows) / totalrows; + int first_row = openfile->edittop->lineno; + + if (ISSET(SOFTWRAP)) { + totalrows = openfile->filebot->chunk_nr + + number_of_chunks_in(openfile->filebot); + first_row = openfile->edittop->chunk_nr + + chunk_for(openfile->firstcolumn, openfile->edittop); + } + + int lowest = ((first_row - 1) * editwinrows) / totalrows; int highest = lowest + (editwinrows * editwinrows) / totalrows; if (editwinrows > totalrows) -- 2.25.4