Merge branch '2661_mcedit_paste'

* 2661_mcedit_paste:
  Handle newline and tab with shift/ctrl modifiers correctly.
  Support bracketed paste mode of xterm in mcedit.
  Ticket #2661: support enable bracketed paste of xterm.
This commit is contained in:
Andrew Borodin 2013-10-03 11:42:07 +04:00
commit c55b4808f6
13 changed files with 86 additions and 22 deletions

View File

@ -61,7 +61,9 @@ Antonio Palama, DOS port <palama@posso.dm.unipi.it>
Egmont Koblinger <egmont@gmail.com>
Support of 256 colors
Support of extended mouse clicks beyond 223
Support of extended mouse clicks beyond 223 column
Support of bracketed paste mode of xterm
(http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Bracketed%20Paste%20Mode)
Erwin van Eijk <wabbit@corner.iaf.nl>

View File

@ -12,6 +12,7 @@
Norbert Warmuth, 1997
Denys Vlasenko <vda.linux@googlemail.com>, 2013
Slava Zanko <slavazanko@gmail.com>, 2013
Egmont Koblinger <egmont@gmail.com>, 2013
This file is part of the Midnight Commander.
@ -92,6 +93,8 @@ int old_esc_mode = 0;
int old_esc_mode_timeout = 1000000; /* settable via env */
int use_8th_bit_as_meta = 0;
gboolean bracketed_pasting_in_progress = FALSE;
/* This table is a mapping between names and the constants we use
* We use this to allow users to define alternate definitions for
* certain keys that may be missing from the terminal database
@ -275,6 +278,8 @@ typedef int (*ph_pqc_f) (unsigned short, PhCursorInfo_t *);
static key_define_t mc_default_keys[] = {
{ESC_CHAR, ESC_STR, MCKEY_ESCAPE},
{ESC_CHAR, ESC_STR ESC_STR, MCKEY_NOACTION},
{MCKEY_BRACKETED_PASTING_START, ESC_STR "[200~", MCKEY_NOACTION},
{MCKEY_BRACKETED_PASTING_END, ESC_STR "[201~", MCKEY_NOACTION},
{0, NULL, MCKEY_NOACTION},
};
@ -326,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},
@ -1008,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 */
@ -2145,7 +2144,17 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block)
{
/* Mouse event */
xmouse_get_event (event, c == MCKEY_EXTENDED_MOUSE);
return (event->type != 0) ? EV_MOUSE : EV_NONE;
c = (event->type != 0) ? EV_MOUSE : EV_NONE;
}
else if (c == MCKEY_BRACKETED_PASTING_START)
{
bracketed_pasting_in_progress = TRUE;
c = EV_NONE;
}
else if (c == MCKEY_BRACKETED_PASTING_END)
{
bracketed_pasting_in_progress = FALSE;
c = EV_NONE;
}
return c;
@ -2250,3 +2259,22 @@ application_keypad_mode (void)
}
/* --------------------------------------------------------------------------------------------- */
void
enable_bracketed_paste (void)
{
printf (ESC_STR "[?2004h");
fflush (stdout);
}
/* --------------------------------------------------------------------------------------------- */
void
disable_bracketed_paste (void)
{
printf (ESC_STR "[?2004l");
fflush (stdout);
bracketed_pasting_in_progress = FALSE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -36,6 +36,10 @@
/* Return code for the extended mouse sequence */
#define MCKEY_EXTENDED_MOUSE -3
/* Return code for brackets of bracketed paste mode */
#define MCKEY_BRACKETED_PASTING_START -4
#define MCKEY_BRACKETED_PASTING_END -5
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
@ -61,6 +65,8 @@ extern int old_esc_mode;
extern int use_8th_bit_as_meta;
extern int mou_auto_repeat;
extern gboolean bracketed_pasting_in_progress;
/*** declarations of public functions ************************************************************/
gboolean define_sequence (int code, const char *seq, int action);
@ -101,6 +107,10 @@ int get_key_code (int nodelay);
void numeric_keypad_mode (void);
void application_keypad_mode (void);
/* Bracketed paste mode */
void enable_bracketed_paste (void);
void disable_bracketed_paste (void);
/*** inline functions ****************************************************************************/
static inline gboolean

View File

@ -218,6 +218,7 @@ void
tty_shutdown (void)
{
disable_mouse ();
disable_bracketed_paste ();
tty_reset_shell_mode ();
tty_noraw_mode ();
tty_keypad (FALSE);

View File

@ -347,6 +347,7 @@ tty_shutdown (void)
char *op_cap;
disable_mouse ();
disable_bracketed_paste ();
tty_reset_shell_mode ();
tty_noraw_mode ();
tty_keypad (FALSE);

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

@ -3457,14 +3457,14 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
if (option_auto_para_formatting)
{
edit_double_newline (edit);
if (option_return_does_auto_indent)
if (option_return_does_auto_indent && !bracketed_pasting_in_progress)
edit_auto_indent (edit);
format_paragraph (edit, FALSE);
}
else
{
edit_insert (edit, '\n');
if (option_return_does_auto_indent)
if (option_return_does_auto_indent && !bracketed_pasting_in_progress)
edit_auto_indent (edit);
}
break;

View File

@ -1065,6 +1065,15 @@ edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v
ret = edit_dialog_command_execute (h, command);
}
/*
* Due to the "end of bracket" escape the editor sees input with is_idle() == false
* (expects more characters) and hence doesn't yet refresh the screen, but then
* no further characters arrive (there's only an "end of bracket" which is swallowed
* by tty_get_event()), so you end up with a screen that's not refreshed after pasting.
* So let's trigger an IDLE signal.
*/
if (!is_idle ())
widget_want_idle (w, TRUE);
return ret;
}
@ -1080,6 +1089,11 @@ edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v
edit_dlg_deinit ();
return MSG_HANDLED;
case MSG_IDLE:
widget_want_idle (w, FALSE);
edit_update_screen ((WEdit *) h->current->data);
return MSG_HANDLED;
default:
return dlg_default_callback (w, sender, msg, parm, data);
}

View File

@ -88,6 +88,7 @@ edition_post_exec (void)
tty_raw_mode ();
channels_up ();
enable_mouse ();
enable_bracketed_paste ();
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();
}
@ -107,6 +108,7 @@ edition_pre_exec (void)
channels_down ();
disable_mouse ();
disable_bracketed_paste ();
tty_reset_shell_mode ();
tty_keypad (FALSE);
@ -455,6 +457,7 @@ toggle_panels (void)
channels_down ();
disable_mouse ();
disable_bracketed_paste ();
if (clear_before_exec)
clr_scr ();
if (mc_global.tty.alternate_plus_minus)
@ -518,6 +521,7 @@ toggle_panels (void)
}
enable_mouse ();
enable_bracketed_paste ();
channels_up ();
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();

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

View File

@ -381,6 +381,10 @@ main (int argc, char *argv[])
w/o Shift button in subshell in the native console */
init_mouse ();
/* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is
separate for the normal and alternate screens */
enable_bracketed_paste ();
/* subshell_prompt is NULL here */
mc_prompt = (geteuid () == 0) ? "# " : "$ ";