From 95989e7dfe9da043d6ccd7f16372ccc36d872e9b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 18 Mar 2018 13:44:57 +0100
Subject: [PATCH] selecting: don't cancel a softmark when just scrolling the
 screen

As, since commit 0e30177d, the scrollup and scrolldown commands
no longer intend to move the cursor, they should not be seen as
movement functions.

Also, it is not guaranteed that functions are ordered in the same
way in the binary as in the source code, so an ordered comparison
of function pointers will not always work.

This fixes https://savannah.gnu.org/bugs/?53333.
---
 src/nano.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 1c7c4dec..7835af5c 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1621,6 +1621,19 @@ int do_mouse(void)
 }
 #endif /* ENABLE_MOUSE */
 
+/* Return TRUE when the given function is a cursor-moving command. */
+bool wanted_to_move(void *func)
+{
+	return func == do_left || func == do_right ||
+			func == do_up || func == do_down ||
+			func == do_home || func == do_end ||
+			func == do_prev_word_void || func == do_next_word_void ||
+			func == do_para_begin_void || func == do_para_end_void ||
+			func == do_prev_block || func == do_next_block ||
+			func == do_page_up || func == do_page_down ||
+			func == to_first_line || func == to_last_line;
+}
+
 /* Read in a keystroke.  Act on the keystroke if it is a shortcut or a toggle;
  * otherwise, insert it into the edit buffer.  If allow_funcs is FALSE, don't
  * do anything with the keystroke -- just return it. */
@@ -1770,8 +1783,7 @@ int do_input(bool allow_funcs)
 				if (!shift_held && openfile->kind_of_mark == SOFTMARK &&
 									(openfile->current != was_current ||
 									openfile->current_x != was_x ||
-									(shortcut->func >= to_first_line &&
-									shortcut->func <= do_right))) {
+									wanted_to_move(shortcut->func))) {
 					openfile->mark = NULL;
 					refresh_needed = TRUE;
 				} else if (openfile->current != was_current)
-- 
GitLab