nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 0e4cbd4bfd2c40c99710f894f5f3d5a4cfe1b816
parent ce68f81b2bb1517a6f9b781cad9ed480db299b9e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 18 Jul 2017 12:51:07 +0200

softwrap: when possible, go back a whole bunch of chunks at a time

This improves https://savannah.gnu.org/bugs/?51479 for the +-1 case.

Diffstat:
Msrc/winio.c | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/winio.c b/src/winio.c @@ -2805,25 +2805,25 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge) #ifndef NANO_TINY if (ISSET(SOFTWRAP)) { - size_t current_leftedge = *leftedge; - /* Recede through the requested number of chunks. */ for (i = nrows; i > 0; i--) { - if (current_leftedge > 0) { - current_leftedge = leftedge_for(current_leftedge - 1, *line); - continue; - } + size_t chunk = chunk_for(*leftedge, *line); + + *leftedge = 0; + + if (chunk >= i) + return go_forward_chunks(chunk - i, line, leftedge); if (*line == openfile->fileage) break; + i -= chunk; *line = (*line)->prev; - current_leftedge = leftedge_for((size_t)-1, *line); + *leftedge = HIGHEST_POSITIVE; } - /* Only change leftedge when we actually could move. */ - if (i < nrows) - *leftedge = current_leftedge; + if (*leftedge == HIGHEST_POSITIVE) + *leftedge = leftedge_for(*leftedge, *line); } else #endif for (i = nrows; i > 0 && (*line)->prev != NULL; i--)