From ec5c28899684308a599ac3e6f8cc0e571aa605ce Mon Sep 17 00:00:00 2001
From: Benno Schulenberg
Date: Fri, 5 Oct 2018 19:50:41 +0200
Subject: [PATCH] bindings: make the Shift+arrow keys work by default on more
terminals
Ask ncurses for the codes for the Shift+arrow keys, so that also
and can be recognized, for which ncurses
doesn't have standard codes.
This fixes https://savannah.gnu.org/bugs/?54790.
Reported-by: Javier Valencia
---
src/global.c | 1 +
src/nano.c | 5 +++++
src/nano.h | 4 ++++
src/proto.h | 4 ++++
src/winio.c | 14 +++++++++++++-
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/global.c b/src/global.c
index 9aebe36f..1fd55156 100644
--- a/src/global.c
+++ b/src/global.c
@@ -71,6 +71,7 @@ int didfind = 0;
int controlleft, controlright, controlup, controldown, controlhome, controlend;
int controldelete, controlshiftdelete;
#ifndef NANO_TINY
+int shiftleft, shiftright, shiftup, shiftdown;
int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown;
int shiftcontrolhome, shiftcontrolend;
int altleft, altright, altup, altdown;
diff --git a/src/nano.c b/src/nano.c
index 89aaf0f3..5c9730c4 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2579,6 +2579,11 @@ int main(int argc, char **argv)
#ifndef NANO_TINY
controldelete = get_keycode("kDC5", CONTROL_DELETE);
controlshiftdelete = get_keycode("kDC6", CONTROL_SHIFT_DELETE);
+ /* Ask for the codes for Shift+Left/Right/Up/Down. */
+ shiftleft = get_keycode("kLFT", SHIFT_LEFT);
+ shiftright = get_keycode("kRIT", SHIFT_RIGHT);
+ shiftup = get_keycode("kUP", SHIFT_UP);
+ shiftdown = get_keycode("kDN", SHIFT_DOWN);
/* Ask for the codes for Shift+Control+Left/Right/Up/Down. */
shiftcontrolleft = get_keycode("kLFT6", SHIFT_CONTROL_LEFT);
shiftcontrolright = get_keycode("kRIT6", SHIFT_CONTROL_RIGHT);
diff --git a/src/nano.h b/src/nano.h
index 3beffe43..480e4c3c 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -597,6 +597,10 @@ enum
#define SHIFT_ALT_RIGHT 0x432
#define SHIFT_ALT_UP 0x433
#define SHIFT_ALT_DOWN 0x434
+#define SHIFT_LEFT 0x451
+#define SHIFT_RIGHT 0x452
+#define SHIFT_UP 0x453
+#define SHIFT_DOWN 0x454
#define SHIFT_HOME 0x455
#define SHIFT_END 0x456
#define SHIFT_PAGEUP 0x457
diff --git a/src/proto.h b/src/proto.h
index ec25c931..35ac4562 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -64,6 +64,10 @@ extern int controlend;
#ifndef NANO_TINY
extern int controldelete;
extern int controlshiftdelete;
+extern int shiftleft;
+extern int shiftright;
+extern int shiftup;
+extern int shiftdown;
extern int shiftcontrolleft;
extern int shiftcontrolright;
extern int shiftcontrolup;
diff --git a/src/winio.c b/src/winio.c
index 8ba37e42..10331e28 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -543,7 +543,19 @@ int parse_kbinput(WINDOW *win)
return CONTROL_DELETE;
else if (retval == controlshiftdelete)
return CONTROL_SHIFT_DELETE;
- else if (retval == shiftcontrolleft) {
+ else if (retval == shiftleft) {
+ shift_held = TRUE;
+ return KEY_LEFT;
+ } else if (retval == shiftright) {
+ shift_held = TRUE;
+ return KEY_RIGHT;
+ } else if (retval == shiftup) {
+ shift_held = TRUE;
+ return KEY_UP;
+ } else if (retval == shiftdown) {
+ shift_held = TRUE;
+ return KEY_DOWN;
+ } else if (retval == shiftcontrolleft) {
shift_held = TRUE;
return CONTROL_LEFT;
} else if (retval == shiftcontrolright) {
--
2.17.1