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 <aborodin@vmail.ru>
This commit is contained in:
Egmont Koblinger 2013-10-01 14:09:14 +04:00 committed by Andrew Borodin
parent 5b47861101
commit 930f683019
5 changed files with 12 additions and 18 deletions

View File

@ -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 */

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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"},