From: Chris Allegretta Date: Sun, 30 Aug 2009 03:50:16 +0000 (+0000) Subject: 2009-08-29 Chris Allegretta X-Git-Tag: v2.1.11~6 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=139934a2361129c61b62c797f57233a052962165;p=nano.git 2009-08-29 Chris Allegretta * Fix more soft wrapping issues, particularly with soft scrolling, discovered by Hannes . git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4405 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 1fad54d0..70158adf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-08-29 Chris Allegretta + * Fix more soft wrapping issues, particularly with soft scrolling, + discovered by Hannes . + 2009-08-19 Chris Allegretta * Fix issue with soft wrapping not displaying the last character of each line, fixed bug discovered by Hannes . diff --git a/src/move.c b/src/move.c index 531a48cb..fba776b4 100644 --- a/src/move.c +++ b/src/move.c @@ -550,23 +550,41 @@ void do_down( #endif ) { + bool onlastline = FALSE; + /* If we're at the bottom of the file, get out. */ if (openfile->current == openfile->filebot) return; - assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); + + assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); /* Move the current line of the edit window down. */ openfile->current = openfile->current->next; openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); + if (ISSET(SOFTWRAP)) { + filestruct *foo; + ssize_t extracuzsoft = 0; + + for (foo = openfile->edittop; foo + && foo->lineno - openfile->edittop->lineno + extracuzsoft < editwinrows; + foo = foo->next) { + extracuzsoft += strlenpt(foo->data) / (COLS - 1); + if (foo == openfile->current) + break; + } + if (foo && foo->lineno - openfile->edittop->lineno + extracuzsoft >= editwinrows) + onlastline = TRUE; + } + /* If scroll_only is FALSE and if we're on the first line of the * edit window, scroll the edit window down one line if we're in * smooth scrolling mode, or down half a page if we're not. If * scroll_only is TRUE, scroll the edit window down one line * unconditionally. */ - if (openfile->current_y == editwinrows - 1 + if (onlastline || openfile->current_y == editwinrows - 1 #ifndef NANO_TINY || scroll_only #endif @@ -581,7 +599,7 @@ void do_down( * we were on before and the line we're on now. The former needs to * be redrawn if we're not on the first page, and the latter needs * to be drawn unconditionally. */ - if (openfile->current_y < editwinrows - 1) { + if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) { if (need_vertical_update(0)) update_line(openfile->current->prev, 0); update_line(openfile->current, openfile->current_x); diff --git a/src/winio.c b/src/winio.c index ce73b997..3835601a 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2439,7 +2439,7 @@ void reset_cursor(void) if (ISSET(SOFTWRAP)) { openfile->current_y = 0; filestruct *tmp; - for (tmp = openfile->edittop; tmp != openfile->current; tmp = tmp->next) + for (tmp = openfile->edittop; tmp && tmp != openfile->current; tmp = tmp->next) openfile->current_y += 1 + strlenpt(tmp->data) / (COLS - 1); openfile->current_y += xplustabs() / (COLS - 1); @@ -2842,19 +2842,12 @@ int update_line(filestruct *fileptr, size_t index) assert(fileptr != NULL); if (ISSET(SOFTWRAP)) { - for (tmp = openfile->edittop; tmp != fileptr; tmp = tmp->next) { + for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) { line += 1 + (strlenpt(tmp->data) / COLS); -#ifdef DEBUG - fprintf(stderr, "update_line(): inside loop, line = %d\n", line); -#endif } } else line = fileptr->lineno - openfile->edittop->lineno; -#ifdef DEBUG - fprintf(stderr, "update_line(): line = %d\n", line); -#endif - if (line < 0 || line >= editwinrows) return; @@ -2938,14 +2931,46 @@ bool need_vertical_update(size_t pww_save) * also assume that scrollok(edit) is FALSE. */ void edit_scroll(scroll_dir direction, ssize_t nlines) { - bool do_redraw = need_vertical_update(0); filestruct *foo; - ssize_t i; + ssize_t i, extracuzsoft = 0; + bool do_redraw = FALSE; /* Don't bother scrolling less than one line. */ if (nlines < 1) return; + if (need_vertical_update(0) || ISSET(SOFTWRAP) && strlen(openfile->edittop->data) / (COLS - 1) > 1) + do_redraw = TRUE; + + + /* If using soft wrapping, we want to scroll down enough to display the entire next + line, if possible... */ + if (ISSET(SOFTWRAP)) { +#ifdef DEBUG + fprintf(stderr, "Softwrap: Entering check for extracuzsoft\n"); +#endif + for (i = editwinrows, foo = openfile->edittop; foo && i > 0; i--, foo = foo->next) + i -= strlenpt(foo->data) / (COLS - 1); + if (foo) { + extracuzsoft += strlenpt(foo->data) / (COLS - 1); +#ifdef DEBUG + fprintf(stderr, "Setting extracuzsoft to %zd due to strlen %zd of line %zd\n", extracuzsoft, + strlenpt(foo->data), foo->lineno); +#endif + /* Now account for whether the edittop line itself is >COLS, if scrolling down */ + for (foo = openfile->edittop; direction != UP_DIR && foo && extracuzsoft > 0; nlines++) { + extracuzsoft -= strlenpt(foo->data) / (COLS - 1) + 1; +#ifdef DEBUG + fprintf(stderr, "Edittop adjustment, setting nlines to %zd\n", nlines); +#endif + if (foo == openfile->filebot) + break; + foo = foo->next; + } + } + } + + /* Part 1: nlines is the number of lines we're going to scroll the * text of the edit window. */ @@ -2970,7 +2995,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines) /* Don't bother scrolling zero lines or more than the number of * lines in the edit window minus one; in both cases, get out, and * call edit_refresh() beforehand if we need to. */ - if (nlines == 0 || nlines >= editwinrows) { + if (nlines == 0 || do_redraw || nlines >= editwinrows) { if (do_redraw || nlines >= editwinrows) edit_refresh(); return; @@ -3039,6 +3064,7 @@ void edit_redraw(filestruct *old_current, size_t pww_save) bool do_redraw = need_vertical_update(0) || need_vertical_update(pww_save); filestruct *foo = NULL; + ssize_t i = 0, extracuzsoft = 0; /* If either old_current or current is offscreen, scroll the edit * window until it's onscreen and get out. */ @@ -3047,6 +3073,7 @@ void edit_redraw(filestruct *old_current, size_t pww_save) editwinrows || openfile->current->lineno < openfile->edittop->lineno || openfile->current->lineno >= openfile->edittop->lineno + editwinrows) { + filestruct *old_edittop = openfile->edittop; ssize_t nlines;