nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] input: scroll on mousewheel instead of moving cursor


From: Andy Koppe
Subject: [PATCH] input: scroll on mousewheel instead of moving cursor
Date: Tue, 12 Sep 2023 03:47:54 +0100

Scroll on mousewheel events instead of moving the cursor, by translating
such events into Alt+Up/Down arrow keys instead of plain Up/Down, as the
latter only start scrolling once the cursor reaches the top or bottom.

Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---
Scrolling rather than moving the cursor is the standard behavior for
mousewheel events both in GUI editors such as Gedit, Kate, Notepad/++
and the GUI versions of vim and emacs, as well as in the mouse mode of
terminal editors such as vim, mcedit, mined and joe. (The terminal
version of emacs doesn't bind the mousewheel events by default.)

 src/winio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/winio.c b/src/winio.c
index 4831cb8d..af6a0b29 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1570,9 +1570,9 @@ char *get_verbatim_kbinput(WINDOW *frame, size_t *count)
  * TRUE, releasing/clicking on a visible shortcut will put back the
  * keystroke associated with that shortcut.  If ncurses supports them,
  * we also handle presses of the fourth mouse button (upward rolls of
- * the mouse wheel) by putting back keystrokes to move up, and presses
+ * the mouse wheel) by putting back keystrokes to scroll up, and presses
  * of the fifth mouse button (downward rolls of the mouse wheel) by
- * putting back keystrokes to move down.  We also store the coordinates
+ * putting back keystrokes to scroll down.  We also store the coordinates
  * of a mouse event that needs further handling in mouse_x and mouse_y.
  * Return -1 on error, 0 if the mouse event needs to be handled, 1 if it's
  * been handled by putting back keystrokes, or 2 if it's been ignored. */
@@ -1670,9 +1670,9 @@ int get_mouseinput(int *mouse_y, int *mouse_x, bool 
allow_shortcuts)
                        wmouse_trafo(footwin, mouse_y, mouse_x, FALSE);
 
                if (in_middle || (in_footer && *mouse_y == 0)) {
-                       int keycode = (event.bstate & BUTTON4_PRESSED) ? KEY_UP 
: KEY_DOWN;
+                       int keycode = (event.bstate & BUTTON4_PRESSED) ? ALT_UP 
: ALT_DOWN;
 
-                       /* One roll of the mouse wheel should move three lines. 
*/
+                       /* One roll of the mouse wheel should scroll three 
lines. */
                        for (int count = 3; count > 0; count--)
                                put_back(keycode);
 
-- 
2.42.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]