diff --git a/ChangeLog b/ChangeLog index 300d25f4add5b3d0b40e4f2cf7043100dc73ac6b..3224f2bd425063286f6631459c4890be889f2047 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-11-23 Benno Schulenberg <bensberg@justemail.net> + * 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 <bensberg@justemail.net> * 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 73a93bba7822a0f8ae2f6978a61a5c16aef157b7..cdc6e9946e529cdc1d4a704ce294623797a1f7a8 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 56a7c1ada09686e1960606ea9ebed2ff5de2659c..2d75f2b658c3041df892c7cff5dbd07cac950934 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 422004aac57e23fcf9371b38fe70f42f39a00886..e2cbf3d5dea6e63d28af1f0e06eee413b3c5f1db 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 b6343cdeb6bf96e0c5280c2a9043e450841e7843..e0a66b834559d1bd31d210e01349e1f06e8c076e 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 799be5d2658c7a30222722afce732f24ae32a857..225ca722800c81ef712aca51db90551576ce8a52 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)