From d7fbc70a72a074464276f0aa5658b5859d03be2a Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 2 Jan 2017 13:41:27 -0600
Subject: [PATCH] tweaks: avoid an unnecessary fiddling with current_y in
 do_mouse()

Since do_mouse() uses edit_redraw(), openfile->current_y will be
immediately recalculated, so there's no point in changing it now.
Use a temporary variable instead.
---
 src/nano.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 64895412..6f8a46d3 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1752,12 +1752,12 @@ int do_mouse(void)
 
 #ifndef NANO_TINY
 	if (ISSET(SOFTWRAP)) {
-	    ssize_t i = 0;
+	    ssize_t i = 0, current_row = 0;
 
 	    openfile->current = openfile->edittop;
 
 	    while (openfile->current->next != NULL && i < mouse_y) {
-		openfile->current_y = i;
+		current_row = i;
 		i += strlenpt(openfile->current->data) / editwincols + 1;
 		openfile->current = openfile->current->next;
 	    }
@@ -1765,18 +1765,20 @@ int do_mouse(void)
 	    if (i > mouse_y) {
 		openfile->current = openfile->current->prev;
 		openfile->current_x = actual_x(openfile->current->data,
-			((mouse_y - openfile->current_y) * editwincols) + mouse_x);
+			((mouse_y - current_row) * editwincols) + mouse_x);
 	    } else
 		openfile->current_x = actual_x(openfile->current->data, mouse_x);
 	} else
 #endif /* NANO_TINY */
 	{
+	    ssize_t current_row = openfile->current_y;
+
 	    /* Move to where the click occurred. */
-	    for (; openfile->current_y < mouse_y && openfile->current !=
-			openfile->filebot; openfile->current_y++)
+	    for (; current_row < mouse_y && openfile->current !=
+			openfile->filebot; current_row++)
 		openfile->current = openfile->current->next;
-	    for (; openfile->current_y > mouse_y && openfile->current !=
-			openfile->fileage; openfile->current_y--)
+	    for (; current_row > mouse_y && openfile->current !=
+			openfile->fileage; current_row--)
 		openfile->current = openfile->current->prev;
 
 	    openfile->current_x = actual_x(openfile->current->data,
-- 
GitLab