From 06920d7d9dff2a8f00f5aaf7d657109219fe2edf Mon Sep 17 00:00:00 2001
From: Arun Prakash Jana <engineerarun@gmail.com>
Date: Wed, 25 Dec 2019 22:18:36 +0530
Subject: [PATCH] Revert "Fix #420: reduce Lead key to bookmark key"

This reverts commit 1ed5febe0c298cc932a2127b8ba061fe941ea379.
---
 nnn.1     |  2 +-
 src/nnn.c | 61 ++++++++++++++++++++++++++++++++++++++++---------------
 src/nnn.h |  8 ++++----
 3 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/nnn.1 b/nnn.1
index 6782c5ea..9b8a806c 100644
--- a/nnn.1
+++ b/nnn.1
@@ -179,7 +179,7 @@ when dealing with the !, e and p commands respectively. A single combination to
 .Bd -literal
     export NNN_BMS='d:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/'
 
-    NOTE: To go to a bookmark, press the Go to bookmark shortcut followed by the key.
+    NOTE: To go to a bookmark, press the Lead key followed by the bookmark key.
 .Ed
 .Pp
 \fBNNN_PLUG:\fR directly executable plugins as \fIkey_char:location\fR pairs (max 10) separated by
diff --git a/src/nnn.c b/src/nnn.c
index a3ab3534..a4207778 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -2127,7 +2127,7 @@ static int filterentries(char *path)
 		}
 	}
 end:
-	if (*ch != '\t' && *ch != 27)
+	if (*ch != '\t' && *ch != CONTROL('_'))
 		g_ctx[cfg.curctx].c_fltr[0] = g_ctx[cfg.curctx].c_fltr[1] = '\0';
 
 	move_cursor(cur, 0);
@@ -3474,8 +3474,8 @@ static void show_help(const char *path)
 	       "9g ^A  Top%-11cRet Right l  Open\n"
 	       "9G ^E  Bottom%-18c'  First file\n"
 		  "cb  Pin CWD%-16c^B  Go to pinned dir\n"
-	       "9, ^/  Go to bookmark%-10cd  Detail view toggle\n"
-	    "6(Sh)Tab  Cycle context%-11cN  Context N\n"
+	       "9, ^/  Lead key%-10cN LeadN  Context N\n"
+	    "6(Sh)Tab  Cycle context%-11cd  Detail view toggle\n"
 		  "c/  Filter%-13cIns ^N  Nav-as-you-type toggle\n"
 		"aEsc  Exit prompt%-9c^L F5  Redraw/clear prompt\n"
 		  "c.  Toggle hidden%-11c?  Help, conf\n"
@@ -3496,7 +3496,7 @@ static void show_help(const char *path)
 		  "cz  Size%-20ct  Time\n"
 		  "cE  Extension%-1c\n"
 		"1MISC\n"
-	       "9! ^]  Shell%-17c; x  Run plugin\n"
+	       "9! ^]  Shell%-17c; x  Plugin key\n"
 		  "cC  Execute file%-9ci ^V  Pick plugin\n"
 		  "cs  Manage session%-10c=  Launch app\n"
 		  "cc  Connect remote%-10cu  Unmount\n"
@@ -4587,6 +4587,7 @@ nochange:
 			DPRINTF_S(path);
 			setdirwatch();
 			goto begin;
+		case SEL_LEADER: // fallthrough
 		case SEL_CYCLE: // fallthrough
 		case SEL_CYCLER: // fallthrough
 		case SEL_CTX1: // fallthrough
@@ -4594,11 +4595,43 @@ nochange:
 		case SEL_CTX3: // fallthrough
 		case SEL_CTX4:
 			switch (sel) {
-			case SEL_CYCLE: // fallthrough
+			case SEL_CYCLE:
+				fd = '\t';
+				break;
 			case SEL_CYCLER:
+				fd = KEY_BTAB;
+				break;
+			case SEL_CTX1: // fallthrough
+			case SEL_CTX2: // fallthrough
+			case SEL_CTX3: // fallthrough
+			case SEL_CTX4:
+				fd = sel - SEL_CTX1 + '1';
+				break;
+			default:
+				xstrlcpy(g_buf, messages[MSG_BOOKMARK_KEYS], CMD_LEN_MAX);
+				printkeys(bookmark, g_buf + strlen(g_buf), BM_MAX);
+				printprompt(g_buf);
+				fd = get_input(NULL);
+			}
+
+			switch (fd) {
+			case '~': // fallthrough
+			case '`': // fallthrough
+			case '-': // fallthrough
+			case '@':
+				presel = fd;
+				goto nochange;
+			case '.':
+				cfg.showhidden ^= 1;
+				setdirwatch();
+				if (ndents)
+					copycurname();
+				goto begin;
+			case '\t': // fallthrough
+			case KEY_BTAB:
 				/* visit next and previous contexts */
 				r = cfg.curctx;
-				if (sel == SEL_CYCLE)
+				if (fd == '\t')
 					do
 						r = (r + 1) & ~CTX_MAX;
 					while (!g_ctx[r].c_cfg.ctxactive);
@@ -4606,11 +4639,12 @@ nochange:
 					do
 						r = (r + (CTX_MAX - 1)) & (CTX_MAX - 1);
 					while (!g_ctx[r].c_cfg.ctxactive);
-				// fallthrough
-			default: /* SEL_CTXN */
-				if (sel >= SEL_CTX1) /* CYCLE keys are lesser in value */
-					r = sel - SEL_CTX1; /* Save the next context id */
-
+				fd = '1' + r; // fallthrough
+			case '1': // fallthrough
+			case '2': // fallthrough
+			case '3': // fallthrough
+			case '4':
+				r = fd - '1'; /* Save the next context id */
 				if (cfg.curctx == r) {
 					if (sel != SEL_CYCLE)
 						continue;
@@ -4635,11 +4669,6 @@ nochange:
 				setdirwatch();
 				goto begin;
 			}
-		case SEL_BOOKMARK:
-			xstrlcpy(g_buf, messages[MSG_BOOKMARK_KEYS], CMD_LEN_MAX);
-			printkeys(bookmark, g_buf + strlen(g_buf), BM_MAX);
-			printprompt(g_buf);
-			fd = get_input(NULL);
 
 			if (!get_kv_val(bookmark, newpath, fd, BM_MAX, TRUE)) {
 				printwait(messages[MSG_INVALID_KEY], &presel);;
diff --git a/src/nnn.h b/src/nnn.h
index 0a917468..8a495d1d 100644
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -53,13 +53,13 @@ enum action {
 	SEL_CDLAST,
 	SEL_CDROOT,
 	SEL_VISIT,
+	SEL_LEADER,
 	SEL_CYCLE,
 	SEL_CYCLER,
 	SEL_CTX1,
 	SEL_CTX2,
 	SEL_CTX3,
 	SEL_CTX4,
-	SEL_BOOKMARK,
 	SEL_PIN,
 	SEL_FLTR,
 	SEL_MFLTR,
@@ -157,6 +157,9 @@ static struct key bindings[] = {
 	{ '`',            SEL_CDROOT },
 	/* Visit marked directory */
 	{ CONTROL('B'),   SEL_VISIT },
+	/* Leader key */
+	{ CONTROL('_'),   SEL_LEADER },
+	{ ',',            SEL_LEADER },
 	/* Cycle contexts in forward direction */
 	{ '\t',           SEL_CYCLE },
 	/* Cycle contexts in reverse direction */
@@ -166,9 +169,6 @@ static struct key bindings[] = {
 	{ '2',            SEL_CTX2 },
 	{ '3',            SEL_CTX3 },
 	{ '4',            SEL_CTX4 },
-	/* Bookmark key */
-	{ CONTROL('_'),   SEL_BOOKMARK },
-	{ ',',            SEL_BOOKMARK },
 	/* Mark a path to visit later */
 	{ 'b',            SEL_PIN },
 	/* Filter */
-- 
2.51.0