1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 14:56:39 +02:00

core: When pasting, insert text in input instead of interpreting keys

This makes pasted text appear in the input bar, instead of each line
being sent. This allows you to edit the text before sending it, and it
makes multiline paste supported in buffers with input_multiline on.

It also replaces \r with \n in pasted text because most terminals (e.g.
xterm and urxvt) print lines separated by \r when pasting as if return
was pressed between each line, even though the copied text uses \n. The
text sent to the buffer should use \n, not \r, so we have to replace it.

Note that this only works when bracketed paste is enabled or the paste
confirmation as shown, because non-bracketed paste with no paste
confirmation is not detected as a paste.

Fixes a part of #1498
This commit is contained in:
Trygve Aaberge
2020-05-10 12:42:55 +02:00
committed by Sébastien Helleu
parent cfaf68ae61
commit 99f6f9e454
+15 -5
View File
@@ -294,17 +294,27 @@ gui_key_flush (int paste)
for (i = 0; i < gui_key_buffer_size; i++)
{
key = gui_key_buffer[i];
/*
* Many terminal emulators sends \n as \r when pasting, so replace them
* back
*/
if (paste && key == '\r')
{
key = '\n';
}
insert_ok = 1;
utf_partial_char[0] = '\0';
if (gui_mouse_event_pending)
if (!paste && gui_mouse_event_pending)
{
insert_ok = 0;
key_str[0] = (char)key;
key_str[1] = '\0';
length_key_str = 1;
}
else if (key < 32)
else if (!paste && key < 32)
{
insert_ok = 0;
key_str[0] = '\x01';
@@ -319,7 +329,7 @@ gui_key_flush (int paste)
key_str[2] = '\0';
length_key_str = 2;
}
else if (key == 127)
else if (!paste && key == 127)
{
insert_ok = 0;
key_str[0] = '\x01';
@@ -379,7 +389,7 @@ gui_key_flush (int paste)
* or if the mouse code is valid UTF-8 (do not send partial mouse
* code which is not UTF-8 valid)
*/
if (!gui_mouse_event_pending || utf8_is_valid (key_str, -1, NULL))
if (!paste && (!gui_mouse_event_pending || utf8_is_valid (key_str, -1, NULL)))
{
(void) hook_signal_send ("key_pressed",
WEECHAT_HOOK_SIGNAL_STRING, key_str);
@@ -392,7 +402,7 @@ gui_key_flush (int paste)
input_old = NULL;
old_buffer = gui_current_window->buffer;
if ((gui_key_pressed (key_str) != 0) && (insert_ok)
if ((paste || gui_key_pressed (key_str) != 0) && (insert_ok)
&& (!gui_cursor_mode))
{
if (!paste || !undo_done)