From c16e74036e791b2c1f9c19841fc75a60067aefec Mon Sep 17 00:00:00 2001
From: KatolaZ <katolaz@freaknet.org>
Date: Thu, 8 Aug 2019 08:39:04 +0100
Subject: fix bug with global movements in arrow mode

---
 screen.c | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

(limited to 'screen.c')

diff --git a/screen.c b/screen.c
index 587abd7..3c69541 100644
--- a/screen.c
+++ b/screen.c
@@ -252,39 +252,53 @@ void go_to(int where){
 	show_cursor();
 }
 
-void handle_goto(){
+void handle_goto(char global){
 	char c;	
 	c=getchar();
 	switch(c){
 		case 'h':
 			dir = DIR_L;
+			step = x;
 			x = 0;
 			break;
 		case 'l':
 			dir = DIR_R;
+			step = WIDTH - x -1;
 			x = WIDTH - 1;
 			break;
 		case 'j':
 			dir = DIR_D;
+			step = HEIGHT - y-1;
 			y = HEIGHT - 1;
 			break;
 		case 'k':
 			dir = DIR_U;
+			step = y;
 			y = 0;
 			break;
 		case 'g':
-			dir = DIR_N;
-			go_to(HOME);
+			if (global){
+				dir = DIR_N;
+				go_to(HOME);
+			} else step = 0;
 			break;
 		case 'G':
-			dir = DIR_N;
-			go_to(END);
+			if (global){
+				dir = DIR_N;
+				go_to(END);
+			} else step = 0;
 			break;
 		case 'm':
-			dir = DIR_N;
-			go_to(MIDDLE);
+			if (global){
+				dir = DIR_N;
+				go_to(MIDDLE);
+			} else step = 0;
 			break;
 	}
+
+#ifdef DEBUG
+	fprintf(stderr, "global move: dir: %d x: %d y: %d\n", dir, x, y);
+#endif
 	check_bound(&x, &y);
 	show_cursor();
 }
@@ -324,7 +338,7 @@ int get_escape(FILE *fc){
 }
 
 
-int move_around(char c, FILE *fc){
+int move_around(char c, FILE *fc, char global){
 
 	if (isdigit(c)){
 		if (mult)
@@ -365,7 +379,13 @@ int move_around(char c, FILE *fc){
 			x += step;
 			break;
 		case 'g':
-			handle_goto();
+#ifdef DEBUG
+			fprintf(stderr, "before global: step: %d x: %d y: %d\n", step, x, y);
+#endif
+			handle_goto(global);
+#ifdef DEBUG
+			fprintf(stderr, "after global: step: %d x: %d y: %d\n", step, x, y);
+#endif
 			break;
 		default:
 			return 0;
-- 
cgit v1.2.3