From 930f68301918a2772aea3b600be4288b78cc03fc Mon Sep 17 00:00:00 2001 From: Egmont Koblinger Date: Tue, 1 Oct 2013 14:09:14 +0400 Subject: [PATCH] Handle newline and tab with shift/ctrl modifiers correctly. MC already has its own half-ready trick: when pasting with Shift-Insert, using the X11 extension, the newline ("Enter" as mc calls it) with the Shift modifier pressed gets converted to a "Return", and in the editor the Return character inserts a non-indenting newline. This makes pasting better in terminals not supporting bracketed paste, however, it has some problems that this commit addresses: * Shift+newline gets this special treatment, but Ctrl+newline gets dropped. Hence e.g. when pasting in Gnome-terminal with Ctrl+Shift+V all the newlines will be missing. This commit adds the same non-indenting newline behavior to Ctrl+Newline and Ctrl+Shift+Newline. * The code forgets about Tab that also needs special treatment: - Most terminals send \e[Z on Shift+Tab, this is not handled by MC at all, moreover it causes a hang for about a second. This commit teaches this sequence to MC. This is especially useful when no X11 is available, because there Ctrl+Tab is identical to Tab, so the backwards tab feature is not available. With this commit Shift+Tab becomes a backwards tab too on all terminals that emit \e[Z. - When pasting to the editor, Shift+Tab, Ctrl+Tab and Ctrl+Shift+Tab should all insert a tab for the same reason mentioned at the newline. - It would look inconsistent in the keymap files to have logical code such as "backtab" instead of "shift-tab" and friends, hence get rid of KEY_BTAB and use KEY_M_SHIFT | '\t' instead. Signed-off-by: Andrew Borodin --- lib/tty/key.c | 16 +++++----------- lib/widget/dialog.c | 2 +- misc/mc.default.keymap | 4 ++-- misc/mc.emacs.keymap | 4 ++-- src/keybind-defaults.c | 4 ++-- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/tty/key.c b/lib/tty/key.c index 9db45f402..a24ef56d8 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -331,6 +331,7 @@ static key_define_t xterm_key_defines[] = { {KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, ESC_STR "[1;6B", MCKEY_NOACTION}, {KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, ESC_STR "[1;6C", MCKEY_NOACTION}, {KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, ESC_STR "[1;6D", MCKEY_NOACTION}, + {KEY_M_SHIFT | '\t', ESC_STR "[Z", MCKEY_NOACTION}, /* putty */ {KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, ESC_STR "[[1;6A", MCKEY_NOACTION}, @@ -1013,18 +1014,11 @@ correct_key_code (int code) if (c == KEY_SCANCEL) c = '\t'; - /* Convert Shift+Tab and Ctrl+Tab to Back Tab - * only if modifiers directly from X11 - */ -#ifdef HAVE_TEXTMODE_X11_SUPPORT - if (x11_window != 0) -#endif /* HAVE_TEXTMODE_X11_SUPPORT */ + /* Convert Back Tab to Shift+Tab */ + if (c == KEY_BTAB) { - if ((c == '\t') && (mod & (KEY_M_SHIFT | KEY_M_CTRL))) - { - c = KEY_BTAB; - mod = 0; - } + c = '\t'; + mod = KEY_M_SHIFT; } /* F0 is the same as F10 for out purposes */ diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 8d30dfc61..c3cdd04ac 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -493,7 +493,7 @@ dlg_key_event (WDialog * h, int d_key) dlg_one_down (h); return; } - else if (d_key == KEY_BTAB) + else if ((d_key & ~(KEY_M_SHIFT | KEY_M_CTRL)) == '\t') { dlg_one_up (h); return; diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap index 9d1bb60a2..f627fad31 100644 --- a/misc/mc.default.keymap +++ b/misc/mc.default.keymap @@ -227,14 +227,14 @@ Right = right WordLeft = ctrl-left; ctrl-z WordRight = ctrl-right; ctrl-x Enter = enter -Return = shift-enter +Return = shift-enter; ctrl-enter; ctrl-shift-enter BackSpace = backspace; ctrl-h Delete = delete; ctrl-d PageUp = pgup PageDown = pgdn Home = home End = end -Tab = tab +Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab Undo = ctrl-u Redo = alt-r Top = ctrl-home; alt-lt diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap index 6d503b413..1f8977368 100644 --- a/misc/mc.emacs.keymap +++ b/misc/mc.emacs.keymap @@ -227,14 +227,14 @@ Right = right; ctrl-f WordLeft = ctrl-left; alt-b WordRight = ctrl-right; alt-f Enter = enter -Return = shift-enter +Return = shift-enter; ctrl-enter; ctrl-shift-enter BackSpace = backspace Delete = delete PageUp = pgup; alt-v PageDown = pgdn; ctrl-v Home = home; ctrl-a End = end; ctrl-e -Tab = tab +Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab Undo = ctrl-u # Redo = Top = ctrl-home; alt-lt diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c index 7ad1f55f3..040969279 100644 --- a/src/keybind-defaults.c +++ b/src/keybind-defaults.c @@ -320,8 +320,8 @@ static const global_keymap_ini_t default_help_keymap[] = { #ifdef USE_INTERNAL_EDIT static const global_keymap_ini_t default_editor_keymap[] = { {"Enter", "enter"}, - {"Return", "shift-enter"}, /* useful for pasting multiline text */ - {"Tab", "tab"}, + {"Return", "shift-enter; ctrl-enter; ctrl-shift-enter"}, /* useful for pasting multiline text */ + {"Tab", "tab; shift-tab; ctrl-tab; ctrl-shift-tab"}, /* ditto */ {"BackSpace", "backspace; ctrl-h"}, {"Delete", "delete; ctrl-d"}, {"Left", "left"}, -- 2.11.4.GIT