commit b1a7fddc336fe8d72afbcd4d105b109ebebb9652
parent 3ae5bab14e54706122d597f295f961c7050240a3
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 3 Mar 2014 10:02:13 +0000
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
Diffstat:
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,6 +1,9 @@
2014-03-03 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (add_to_funcs) - Add a newline, for clarity.
* 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>
* global.c (shortcut_init) - fix an issue with the split
diff --git a/src/move.c b/src/move.c
@@ -564,7 +564,8 @@ void do_down(
)
{
bool onlastline = FALSE;
- int extra = 0;
+ int amount, enough = 0;
+ filestruct *topline;
/* If we're at the bottom of the file, get out. */
if (openfile->current == openfile->filebot)
@@ -581,11 +582,22 @@ void do_down(
if (ISSET(SOFTWRAP)) {
if (openfile->current->lineno - openfile->edittop->lineno >= maxrows)
onlastline = TRUE;
- /* Compute the extra amount to scroll when the current line is overlong. */
- extra = (strlenpt(openfile->current->data) / COLS + openfile->current_y + 2 - editwinrows);
+ /* Compute the amount to scroll. */
+ 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
* smooth scrolling mode, or down half a page if we're not. If
* scroll_only is TRUE, scroll the edit window down one line
@@ -597,13 +609,13 @@ void do_down(
) {
edit_scroll(DOWN_DIR,
#ifndef NANO_TINY
- (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
+ (ISSET(SMOOTH_SCROLL) || scroll_only) ? (amount ? amount : 1) :
#endif
editwinrows / 2 + 1);
edit_refresh_needed = TRUE;
- } else if (extra > 0) {
- edit_scroll(DOWN_DIR, extra);
+ } else if (amount > 0) {
+ edit_scroll(DOWN_DIR, amount);
edit_refresh_needed = TRUE;
}
/* If we're above the last line of the edit window, update the line
diff --git a/src/winio.c b/src/winio.c
@@ -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
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
fprintf(stderr, "Softwrap: Entering check for extracuzsoft\n");
#endif
@@ -3041,7 +3043,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
openfile->edittop = openfile->edittop->next;
}
/* Don't over-scroll on long lines */
- if (ISSET(SOFTWRAP)) {
+ if (ISSET(SOFTWRAP) && (direction == UP_DIR)) {
ssize_t len = strlenpt(openfile->edittop->data) / COLS;
i -= len;
if (len > 0)