From c709e2d0204b2c5d9d159ab8f8c6a06200a83758 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 22 Dec 2020 12:20:42 +0100
Subject: [PATCH 04/11] mouse: do not offset the shortcuts by 'margin' when
 using --linenumbers

The bottom window (the prompt bar and the shortcuts) does not shift
its position when line numbers are active, so mouse clicks in this
window should be not be compensated for the line-numbers margin.

This fixes https://savannah.gnu.org/bugs/?59749.
Indirectly-reported-by: ObeliX <ObeliX-@gmx.de>

Bug existed since version 2.7.0, since line numbers were introduced.
---
 src/winio.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/winio.c b/src/winio.c
index 5722d7e6..906ea5b4 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1518,14 +1518,16 @@ char *get_verbatim_kbinput(WINDOW *win, size_t *count)
 int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts)
 {
 	MEVENT mevent;
-	bool in_bottomwin;
+	bool in_editwin, in_bottomwin;
 
 	/* First, get the actual mouse event. */
 	if (getmouse(&mevent) == ERR)
 		return -1;
 
+	in_editwin = wenclose(edit, mevent.y, mevent.x);
+
 	/* Save the screen coordinates where the mouse event took place. */
-	*mouse_x = mevent.x - margin;
+	*mouse_x = mevent.x - (in_editwin ? margin : 0);
 	*mouse_y = mevent.y;
 
 	in_bottomwin = wenclose(bottomwin, *mouse_y, *mouse_x);
@@ -1551,7 +1553,7 @@ int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts)
 			/* Clicks on the status bar are handled elsewhere, so
 			 * restore the untranslated mouse-event coordinates. */
 			if (*mouse_y == 0) {
-				*mouse_x = mevent.x - margin;
+				*mouse_x = mevent.x;
 				*mouse_y = mevent.y;
 				return 0;
 			}
-- 
2.29.2

