From f08d79d20407e06d4a1f0f1687aabca1af5b5b00 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 23 Nov 2015 08:52:23 +0000 Subject: [PATCH] Making Ctrl+Left and Ctrl+Right work on more terminals by asking ncurses for the keycodes. This addresses Debian bug #800681. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5434 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/global.c | 5 +++++ src/nano.c | 8 ++++++++ src/nano.h | 7 +++---- src/proto.h | 5 +++++ src/winio.c | 17 +++++++---------- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 300d25f4..3224f2bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-11-23 Benno Schulenberg + * src/nano.c (main), src/winio.c (parse_kbinput): Make Ctrl+Left and + Ctrl+Right work on more terminals by asking ncurses for the keycodes. + This addresses Debian bug #800681 reported by Arturo Borrero González. + 2015-11-22 Benno Schulenberg * src/text.c (add_undo): Delete a condition that will never occur -- this function is only ever called with PASTE when cutbuffer != NULL. diff --git a/src/global.c b/src/global.c index 73a93bba..cdc6e994 100644 --- a/src/global.c +++ b/src/global.c @@ -41,6 +41,11 @@ bool func_key; bool focusing = FALSE; /* Whether an update of the edit window should center the cursor. */ +#ifndef NANO_TINY +int controlleft = CONTROL_LEFT; +int controlright = CONTROL_RIGHT; +#endif + #ifndef DISABLE_WRAPJUSTIFY ssize_t fill = 0; /* The column where we will wrap lines. */ diff --git a/src/nano.c b/src/nano.c index 56a7c1ad..2d75f2b6 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2712,6 +2712,14 @@ int main(int argc, char **argv) interface_color_pair[FUNCTION_TAG].bright = FALSE; #endif +#if !defined(NANO_TINY) && !defined(USE_SLANG) + /* Ask ncurses for the key codes for Control+Left and Control+Right. */ + if ((int)tigetstr("kLFT5") > 0) + controlleft = key_defined(tigetstr("kLFT5")); + if ((int)tigetstr("kRIT5") > 0) + controlright = key_defined(tigetstr("kRIT5")); +#endif + #ifdef DEBUG fprintf(stderr, "Main: open file\n"); #endif diff --git a/src/nano.h b/src/nano.h index 422004aa..e2cbf3d5 100644 --- a/src/nano.h +++ b/src/nano.h @@ -548,10 +548,9 @@ enum #define NANO_CONTROL_7 31 #define NANO_CONTROL_8 127 -/* Codes for "modified" Arrow keys. Chosen like this because some - * terminals produce them, and they are beyond KEY_MAX of ncurses. */ -#define CONTROL_LEFT 539 -#define CONTROL_RIGHT 554 +/* Codes for "modified" Arrow keys, beyond KEY_MAX of ncurses. */ +#define CONTROL_LEFT 0x401 +#define CONTROL_RIGHT 0x402 #ifndef NANO_TINY /* An imaginary key for when we get a SIGWINCH (window resize). */ diff --git a/src/proto.h b/src/proto.h index b6343cde..e0a66b83 100644 --- a/src/proto.h +++ b/src/proto.h @@ -35,6 +35,11 @@ extern bool meta_key; extern bool func_key; extern bool focusing; +#ifndef NANO_TINY +extern int controlleft; +extern int controlright; +#endif + #ifndef DISABLE_WRAPJUSTIFY extern ssize_t fill; extern ssize_t wrap_at; diff --git a/src/winio.c b/src/winio.c index 799be5d2..225ca722 100644 --- a/src/winio.c +++ b/src/winio.c @@ -634,16 +634,6 @@ int parse_kbinput(WINDOW *win) retval = ERR; break; #endif - case CONTROL_LEFT: -#ifndef NANO_TINY - retval = sc_seq_or(do_prev_word_void, 0); -#endif - break; - case CONTROL_RIGHT: -#ifndef NANO_TINY - retval = sc_seq_or(do_next_word_void, 0); -#endif - break; #ifndef NANO_TINY case KEY_WINCH: retval = KEY_WINCH; @@ -651,6 +641,13 @@ int parse_kbinput(WINDOW *win) #endif } +#ifndef NANO_TINY + if (retval == controlleft) + retval = sc_seq_or(do_prev_word_void, 0); + else if (retval == controlright) + retval = sc_seq_or(do_next_word_void, 0); +#endif + /* If our result is an extended keypad value (i.e. a value * outside of byte range), set func_key to TRUE. */ if (retval != ERR) -- 2.39.5