Correctly computing the needed amount to scroll down

when softwrap is on and there are overlong lines.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4632 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-03-03 10:02:13 +00:00
parent 3ae5bab14e
commit b1a7fddc33
3 changed files with 26 additions and 9 deletions

View File

@ -1,6 +1,9 @@
2014-03-03 Benno Schulenberg <bensberg@justemail.net> 2014-03-03 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (add_to_funcs) - Add a newline, for clarity. * src/global.c (add_to_funcs) - Add a newline, for clarity.
* src/global.c (shortcut_init) - Mark, don't translate yet. * src/global.c (shortcut_init) - Mark, don't translate yet.
* src/move.c (do_down) - Correctly compute the minimum amount
to scroll when softwrap is on and there are overlong lines.
* src/winio.c (edit_scroll) - Disable amount computation here.
2014-03-01 Chris Allegretta <chrisa@asty.org> 2014-03-01 Chris Allegretta <chrisa@asty.org>
* global.c (shortcut_init) - fix an issue with the split * global.c (shortcut_init) - fix an issue with the split

View File

@ -564,7 +564,8 @@ void do_down(
) )
{ {
bool onlastline = FALSE; bool onlastline = FALSE;
int extra = 0; int amount, enough = 0;
filestruct *topline;
/* If we're at the bottom of the file, get out. */ /* If we're at the bottom of the file, get out. */
if (openfile->current == openfile->filebot) if (openfile->current == openfile->filebot)
@ -581,11 +582,22 @@ void do_down(
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
if (openfile->current->lineno - openfile->edittop->lineno >= maxrows) if (openfile->current->lineno - openfile->edittop->lineno >= maxrows)
onlastline = TRUE; onlastline = TRUE;
/* Compute the extra amount to scroll when the current line is overlong. */ /* Compute the amount to scroll. */
extra = (strlenpt(openfile->current->data) / COLS + openfile->current_y + 2 - editwinrows); amount = (strlenpt(openfile->current->data) / COLS + openfile->current_y + 2
+ strlenpt(openfile->current->prev->data) / COLS - editwinrows);
topline = openfile->edittop;
/* Reduce the amount when there are overlong lines at the top. */
for (enough = 1; enough < amount; enough++) {
if (amount <= strlenpt(topline->data) / COLS) {
amount = enough;
break;
}
amount -= strlenpt(topline->data) / COLS;
topline = topline->next;
}
} }
/* If scroll_only is FALSE and if we're on the first line of the /* If scroll_only is FALSE and if we're on the last line of the
* edit window, scroll the edit window down one line if we're in * 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 * smooth scrolling mode, or down half a page if we're not. If
* scroll_only is TRUE, scroll the edit window down one line * scroll_only is TRUE, scroll the edit window down one line
@ -597,13 +609,13 @@ void do_down(
) { ) {
edit_scroll(DOWN_DIR, edit_scroll(DOWN_DIR,
#ifndef NANO_TINY #ifndef NANO_TINY
(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : (ISSET(SMOOTH_SCROLL) || scroll_only) ? (amount ? amount : 1) :
#endif #endif
editwinrows / 2 + 1); editwinrows / 2 + 1);
edit_refresh_needed = TRUE; edit_refresh_needed = TRUE;
} else if (extra > 0) { } else if (amount > 0) {
edit_scroll(DOWN_DIR, extra); edit_scroll(DOWN_DIR, amount);
edit_refresh_needed = TRUE; edit_refresh_needed = TRUE;
} }
/* If we're above the last line of the edit window, update the line /* If we're above the last line of the edit window, update the line

View File

@ -2997,7 +2997,9 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
/* If using soft wrapping, we want to scroll down enough to display the entire next /* If using soft wrapping, we want to scroll down enough to display the entire next
line, if possible... */ line, if possible... */
if (ISSET(SOFTWRAP) && direction == DOWN_DIR) {
/* DEFEAT the extracuzsoft computation for now; the amount should be okay already. */
if (FALSE && ISSET(SOFTWRAP) && direction == DOWN_DIR) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Softwrap: Entering check for extracuzsoft\n"); fprintf(stderr, "Softwrap: Entering check for extracuzsoft\n");
#endif #endif
@ -3041,7 +3043,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
openfile->edittop = openfile->edittop->next; openfile->edittop = openfile->edittop->next;
} }
/* Don't over-scroll on long lines */ /* Don't over-scroll on long lines */
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP) && (direction == UP_DIR)) {
ssize_t len = strlenpt(openfile->edittop->data) / COLS; ssize_t len = strlenpt(openfile->edittop->data) / COLS;
i -= len; i -= len;
if (len > 0) if (len > 0)