From 6f9bb53b2d009adb3e2fded243f2e1e53d17deee Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 20 Jul 2017 19:02:16 -0500 Subject: [PATCH] tweaks: set the target row for smooth scrolling more directly The function place_the_cursor() assumes that the viewport is up to date, i.e., that current is in range of edittop. When uncutting or inserting, however, place_the_cursor() gets called on the out-of-date viewport first, and then a screen refresh is scheduled (which would put the viewport up to date). This is backwards: the refresh should come before the cursor placement, and the only reason it works anyway is because the cap on the number of chunks to move backward papers over the problem by keeping current_y in screen range regardless. Fix this properly by simply setting current_y to the bottom row of the screen instead of calling place_the_cursor(). This value of current_y is only ever used when in smooth scrolling mode and the insertion (or paste) pushed the cursor offscreen. In other situations, this value is overridden when place_the_cursor() gets called after a screen refresh. After that fix, the cap on the number of chunks to move backward is no longer needed. --- src/cut.c | 4 ++-- src/files.c | 4 ++-- src/winio.c | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/cut.c b/src/cut.c index 43f87e2f..b1b3fb58 100644 --- a/src/cut.c +++ b/src/cut.c @@ -291,8 +291,8 @@ void do_uncut_text(void) /* Mark the file as modified. */ set_modified(); - /* Update current_y to account for the inserted lines. */ - place_the_cursor(TRUE); + /* Set the target row for the cursor in case it got pushed offscreen. */ + openfile->current_y = editwinrows - 1; refresh_needed = TRUE; diff --git a/src/files.c b/src/files.c index bac0e1bf..d2a97182 100644 --- a/src/files.c +++ b/src/files.c @@ -1188,8 +1188,8 @@ void do_insertfile(void) openfile->current_x != was_current_x) set_modified(); - /* Update current_y to account for inserted lines. */ - place_the_cursor(TRUE); + /* Set the target row for the cursor when pushed offscreen. */ + openfile->current_y = editwinrows - 1; refresh_needed = TRUE; } diff --git a/src/winio.c b/src/winio.c index eaf528cd..dce6b252 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2803,10 +2803,6 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge) { int i; - /* Don't move more chunks than the window can hold. */ - if (nrows > editwinrows - 1) - nrows = (editwinrows < 2) ? 1 : editwinrows - 1; - #ifndef NANO_TINY if (ISSET(SOFTWRAP)) { /* Recede through the requested number of chunks. */