commit 1570651e3012c395e1555f80aba8d16ba3f11925
parent 456d66b90498f5fe3af9d38f078928a249bd9a68
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sun, 15 Jan 2017 14:38:35 -0600
softwrap: count softwrapped chunks properly in do_gotolinecolumn()
Use go_forward_chunks() to count softwrapped chunks between the current
cursor position and the bottom of the file. Now softwrap mode and
non-softwrap mode behave the same way when moving to a line and column
non-interactively, instead of the former's always centering the screen.
Diffstat:
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/search.c b/src/search.c
@@ -883,17 +883,29 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
openfile->placewewant = column - 1;
/* When the position was manually given, center the target line. */
- if (interactive || ISSET(SOFTWRAP)) {
+ if (interactive) {
adjust_viewport(CENTERING);
refresh_needed = TRUE;
} else {
+ int rows_from_tail;
+
+#ifndef NANO_TINY
+ if (ISSET(SOFTWRAP)) {
+ filestruct *line = openfile->current;
+ size_t leftedge = (xplustabs() / editwincols) * editwincols;
+
+ rows_from_tail = (editwinrows / 2) -
+ go_forward_chunks(editwinrows / 2, &line, &leftedge);
+ } else
+#endif
+ rows_from_tail = openfile->filebot->lineno -
+ openfile->current->lineno;
+
/* If the target line is close to the tail of the file, put the last
- * line of the file on the bottom line of the screen; otherwise, just
+ * line or chunk on the bottom line of the screen; otherwise, just
* center the target line. */
- if (openfile->filebot->lineno - openfile->current->lineno <
- editwinrows / 2) {
- openfile->current_y = editwinrows - openfile->filebot->lineno +
- openfile->current->lineno - 1;
+ if (rows_from_tail < editwinrows / 2) {
+ openfile->current_y = editwinrows - 1 - rows_from_tail;
adjust_viewport(STATIONARY);
} else
adjust_viewport(CENTERING);