1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-30 06:45:25 +00:00

Bracketed paste: Adjust paste line count if there's text after newlines

With bracketed paste, "a\nb" will result in two lines being pasted,
because it's a single thing, with an end marker which the timeout based
pastes don't have.

Due to the way term_gets() counts lines, that input will have
paste_line_count == 1. This can be misleading.

This code adjusts it by looking at the last character, and increasing
the count if it finds anything that isn't a newline.
This commit is contained in:
dequis 2015-12-12 01:44:05 -03:00
parent 38d372eccb
commit e6fa311590

View File

@ -660,6 +660,8 @@ static gboolean paste_timeout(gpointer data)
static void paste_bracketed_end(int i, gboolean rest)
{
unichar last_char;
/* if there's stuff after the end bracket, save it for later */
if (rest) {
unichar *start = ((unichar *) paste_buffer->data) + i + G_N_ELEMENTS(bp_end);
@ -672,6 +674,14 @@ static void paste_bracketed_end(int i, gboolean rest)
/* remove the rest, including the trailing sequence chars */
g_array_set_size(paste_buffer, i);
last_char = g_array_index(paste_buffer, unichar, i - 1);
if (paste_line_count > 0 && last_char != '\n' && last_char != '\r') {
/* there are newlines, but there's also stuff after the newline
* adjust line count to reflect this */
paste_line_count++;
}
/* decide what to do with the buffer */
paste_timeout(NULL);