From 28beb3f9c592792c6fb7bd5c24754c857288250a Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 11 May 2017 22:24:39 +0200 Subject: [PATCH] replacing: don't let placewewant influence the placement of the cursor When spotlighting the string to be replaced, placewewant isn't valid, so tell place_the_cursor() to ignore its value to avoid the cursor getting mistakenly placed at the beginning of the next row. This fixes https://savannah.gnu.org/bugs/?50997. Reported-by: David Lawrence Ramsey --- src/cut.c | 2 +- src/files.c | 2 +- src/nano.c | 2 +- src/proto.h | 2 +- src/text.c | 6 +++--- src/winio.c | 13 +++++++------ 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/cut.c b/src/cut.c index d4e40497..5b70570b 100644 --- a/src/cut.c +++ b/src/cut.c @@ -292,7 +292,7 @@ void do_uncut_text(void) set_modified(); /* Update current_y to account for the inserted lines. */ - place_the_cursor(); + place_the_cursor(TRUE); refresh_needed = TRUE; diff --git a/src/files.c b/src/files.c index 30ad3650..a3ba9de9 100644 --- a/src/files.c +++ b/src/files.c @@ -1198,7 +1198,7 @@ void do_insertfile(void) set_modified(); /* Update current_y to account for inserted lines. */ - place_the_cursor(); + place_the_cursor(TRUE); refresh_needed = TRUE; } diff --git a/src/nano.c b/src/nano.c index d4284b6b..2a13e2da 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2659,7 +2659,7 @@ int main(int argc, char **argv) /* Refresh just the cursor position or the entire edit window. */ if (!refresh_needed) { - place_the_cursor(); + place_the_cursor(TRUE); wnoutrefresh(edit); } else edit_refresh(); diff --git a/src/proto.h b/src/proto.h index 7db0ace2..0581762f 100644 --- a/src/proto.h +++ b/src/proto.h @@ -650,7 +650,7 @@ void warn_and_shortly_pause(const char *msg); void statusline(message_type importance, const char *msg, ...); void bottombars(int menu); void onekey(const char *keystroke, const char *desc, int length); -void place_the_cursor(void); +void place_the_cursor(bool forreal); void edit_draw(filestruct *fileptr, const char *converted, int line, size_t from_col); int update_line(filestruct *fileptr, size_t index); diff --git a/src/text.c b/src/text.c index 251a3e66..7fc58208 100644 --- a/src/text.c +++ b/src/text.c @@ -2439,7 +2439,7 @@ void do_justify(bool full_justify) do { #endif statusbar(_("Can now UnJustify!")); - place_the_cursor(); + place_the_cursor(TRUE); curs_set(1); kbinput = do_input(FALSE); #ifndef NANO_TINY @@ -3311,7 +3311,7 @@ void do_linter(void) } /* Place and show the cursor to indicate the affected line. */ - place_the_cursor(); + place_the_cursor(TRUE); wnoutrefresh(edit); curs_set(1); @@ -3558,7 +3558,7 @@ void do_verbatim_input(void) /* TRANSLATORS: This is displayed when the next keystroke will be * inserted verbatim. */ statusbar(_("Verbatim Input")); - place_the_cursor(); + place_the_cursor(TRUE); curs_set(1); /* Read in all the verbatim characters. */ diff --git a/src/winio.c b/src/winio.c index bf6b5fb6..9f431f95 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1235,7 +1235,7 @@ int parse_escape_sequence(WINDOW *win, int kbinput) suppress_cursorpos = FALSE; lastmessage = HUSH; if (currmenu == MMAIN) { - place_the_cursor(); + place_the_cursor(TRUE); curs_set(1); } } @@ -2271,7 +2271,7 @@ void onekey(const char *keystroke, const char *desc, int length) /* Redetermine current_y from the position of current relative to edittop, * and put the cursor in the edit window at (current_y, "current_x"). */ -void place_the_cursor(void) +void place_the_cursor(bool forreal) { ssize_t row = 0; size_t col, xpt = xplustabs(); @@ -2293,7 +2293,7 @@ void place_the_cursor(void) col = xpt % editwincols; /* If the cursor ought to be in column zero, nudge it there. */ - if (openfile->placewewant % editwincols == 0 && col != 0) { + if (forreal && openfile->placewewant % editwincols == 0 && col != 0) { row++; col = 0; } @@ -2307,7 +2307,8 @@ void place_the_cursor(void) if (row < editwinrows) wmove(edit, row, margin + col); - openfile->current_y = row; + if (forreal) + openfile->current_y = row; } /* edit_draw() takes care of the job of actually painting a line into @@ -3089,7 +3090,7 @@ void edit_refresh(void) while (row < editwinrows) blank_row(edit, row++, 0, COLS); - place_the_cursor(); + place_the_cursor(TRUE); wnoutrefresh(edit); refresh_needed = FALSE; @@ -3248,7 +3249,7 @@ void spotlight(bool active, const char *word) room--; } - place_the_cursor(); + place_the_cursor(FALSE); if (active) wattron(edit, hilite_attribute);