diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-10 12:42:55 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-25 18:53:12 +0100 |
commit | 99f6f9e454adb4385dc6b9db5c2c7ca8d05efa13 (patch) | |
tree | 5a63cf0bf2eeccf3748c629a17778c32c1dcfc94 /src/gui/curses | |
parent | cfaf68ae6172cf37c50d3aaac7ab4e88fa80c8ef (diff) | |
download | weechat-99f6f9e454adb4385dc6b9db5c2c7ca8d05efa13.zip |
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
Diffstat (limited to 'src/gui/curses')
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index 746a93c7a..a24a105dd 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -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) |