[PATCH] possible new feature: clicking in the scrollbar jumps to the corresponding line

Benno Schulenberg <[email protected]> Thu, 20 Nov 2025 10:15:34 +0100
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
With --mouse and --indicator, clicking in the rightmost column of
the edit window (the "scrollbar" area) now makes the cursor jump
to the line that places the indicator at the clicked position.

Inspired-by: Firefox, and originally by tilde and fte.
---
 src/winio.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/winio.c b/src/winio.c
index d74c6fe8..9ebc7283 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1602,6 +1602,14 @@ int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts)
 
 	/* Handle releases/clicks of the first mouse button. */
 	if (event.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
+		/* Clicking in the "scrollbar" goes to the roughly corresponding line. */
+		if (in_middle && sidebar && event.x == (COLS - 1) && currmenu == MMAIN) {
+			wmouse_trafo(midwin, mouse_y, mouse_x, FALSE);
+			*mouse_y += (*mouse_y ? 1 : 0);
+			goto_line_and_column(openfile->filebot->lineno * *mouse_y / editwinrows + 1,
+									openfile->placewewant + 1, TRUE);
+			refresh_needed = TRUE;
+		} else
 		/* If we're allowing shortcuts, and the current shortcut list is
 		 * being displayed on the last two lines of the screen, and the
 		 * first mouse button was released on/clicked inside it, we need
-- 
2.51.2