[PATCH 4/4] display: add extra variable, to avoid one-way toggling of SOLO_SIDESCROLL

Benno Schulenberg <[email protected]> Sun, 18 Jan 2026 10:56:24 +0100
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Panning should not be switched off for the whole session
when the window became too narrow at some point.
---
 src/cut.c        |  2 +-
 src/global.c     |  2 ++
 src/nano.c       | 12 ++++++++----
 src/prototypes.h |  1 +
 src/search.c     |  4 ++--
 src/utils.c      |  2 +-
 src/winio.c      |  8 ++++----
 7 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index 1172d45c..ed7bc159 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -54,7 +54,7 @@ void expunge(undo_type action)
 		if (ISSET(SOFTWRAP) && extra_chunks_in(openfile->current) != old_amount)
 			refresh_needed = TRUE;
 		/* When panning, and we have come near edge of the viewport... */
-		else if (!ISSET(SOLO_SIDESCROLL) && openfile->placewewant < brink + CUSHION)
+		else if (united_sidescroll && openfile->placewewant < brink + CUSHION)
 			refresh_needed = TRUE;
 
 		/* Adjust the mark if it is after the cursor on the current line. */
diff --git a/src/global.c b/src/global.c
index fc2a36de..d4408597 100644
--- a/src/global.c
+++ b/src/global.c
@@ -73,6 +73,8 @@ char *title = NULL;
 bool refresh_needed = FALSE;
 		/* Did a command mangle enough of the buffer that we should
 		 * repaint the screen? */
+bool united_sidescroll = TRUE;
+		/* Whether to scroll all lines sideways.  That is: whether to pan. */
 size_t brink = 0;
 		/* From which column the edit window is drawn (when panning). */
 bool focusing = TRUE;
diff --git a/src/nano.c b/src/nano.c
index 34379685..0d29f3d9 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1553,7 +1553,7 @@ void inject(char *burst, size_t count)
 	openfile->placewewant = xplustabs();
 
 	/* When panning, and we have come near the edge of the viewport... */
-	if (!ISSET(SOLO_SIDESCROLL) && openfile->placewewant > brink + editwincols - CUSHION - 1 )
+	if (united_sidescroll && openfile->placewewant > brink + editwincols - CUSHION - 1 )
 		refresh_needed = TRUE;
 
 #ifndef NANO_TINY
@@ -2687,9 +2687,13 @@ int main(int argc, char **argv)
 		if (currmenu != MMAIN)
 			bottombars(MMAIN);
 
-		/* Fall back to single-line sidescrolling when the window is narrow. */
-		if (editwincols < 2 * CUSHION + 2)
-			SET(SOLO_SIDESCROLL);
+		/* Do sideways scrolling only when the user didn' switch it off,
+		 * when not softwrapping, and the window is wide enough. */
+		if (united_sidescroll != (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP) &&
+									editwincols > 2 * CUSHION + 2)) {
+			united_sidescroll = !united_sidescroll;
+			refresh_needed = TRUE;
+		}
 
 #ifndef NANO_TINY
 		if (ISSET(MINIBAR) && !ISSET(ZERO) && LINES > 1 && lastmessage < REMARK)
diff --git a/src/prototypes.h b/src/prototypes.h
index b8299228..1eda8be7 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -47,6 +47,7 @@ extern int final_status;
 extern bool inhelp;
 extern char *title;
 
+extern bool united_sidescroll;
 extern size_t brink;
 
 extern bool focusing;
diff --git a/src/search.c b/src/search.c
index 3ff1cf04..46cfb7ff 100644
--- a/src/search.c
+++ b/src/search.c
@@ -334,7 +334,7 @@ int findnextstr(const char *needle, bool whole_word_only, int modus,
 		light_to_col = wideness(line->data, found_x + found_len);
 
 		/* When panning, ensure the end of the match will be visible too. */
-		if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP))
+		if (united_sidescroll)
 			brink = get_page_start(light_to_col);
 
 		refresh_needed = TRUE;
@@ -596,7 +596,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
 			light_to_col = wideness(openfile->current->data,
 										openfile->current_x + match_len);
 
-			if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP))
+			if (united_sidescroll)
 				brink = get_page_start(light_to_col);
 
 			/* Refresh the edit window, scrolling it if necessary. */
diff --git a/src/utils.c b/src/utils.c
index 7940d556..953a570f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -343,7 +343,7 @@ char *free_and_assign(char *dest, char *src)
  * displayed in the edit window when the cursor is at the given column. */
 size_t get_page_start(size_t column)
 {
-	if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP)) {
+	if (united_sidescroll) {
 		if (column < CUSHION)
 			return 0;
 		else if (column < brink + CUSHION)
diff --git a/src/winio.c b/src/winio.c
index 91036811..7865d425 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2838,7 +2838,7 @@ int update_line(linestruct *line, size_t index)
 #endif
 
 	row = line->lineno - openfile->edittop->lineno;
-	if (!ISSET(SOLO_SIDESCROLL))
+	if (united_sidescroll)
 		from_col = brink;
 	else
 		from_col = get_page_start(wideness(line->data, index));
@@ -2937,7 +2937,7 @@ bool line_needs_update(const size_t old_column, const size_t new_column)
 #endif
 	if (get_page_start(old_column) == get_page_start(new_column))
 		return FALSE;
-	if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP))
+	if (united_sidescroll)
 		refresh_needed = TRUE;
 
 	return !refresh_needed;
@@ -3349,7 +3349,7 @@ void edit_redraw(linestruct *old_current, update_type manner)
 		adjust_viewport(ISSET(JUMPY_SCROLLING) ? CENTERING : manner);
 		refresh_needed = TRUE;
 		return;
-	} else if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP)) {
+	} else if (united_sidescroll) {
 		refresh_needed = TRUE;
 		return;
 	}
@@ -3392,7 +3392,7 @@ void edit_refresh(void)
 		adjust_viewport((focusing || ISSET(JUMPY_SCROLLING)) ? CENTERING : FLOWING);
 
 	/* When panning, ensure the cursor will be within the viewport. */
-	if (!ISSET(SOLO_SIDESCROLL) && !ISSET(SOFTWRAP))
+	if (united_sidescroll)
 		brink = get_page_start(xplustabs());
 
 #ifdef ENABLE_COLOR
-- 
2.51.2