1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Stop front ends remembering the data of their last paste.

Previously, both the Unix and Windows front ends would respond to a
paste action by retrieving data from the system clipboard, converting
it appropriately, _storing_ it in a persistent dynamic data block
inside the front end, and then calling term_do_paste(term), which in
turn would call back to the front end via get_clip() to retrieve the
current contents of that stored data block.

But, as far as I can tell, this was a completely pointless mechanism,
because after a data block was written into this storage area, it
would be immediately used for exactly one paste, and then never
accessed again until the next paste action caused it to be freed and
replaced with a new chunk of pasted data.

So why on earth was it stored persistently at all, and why that
callback mechanism from frontend to terminal back to frontend to
retrieve it for the actual paste action? I have no idea. This change
removes the entire system and replaces it with the completely obvious
alternative: the character-set-converted version of paste data is
allocated in a _local_ variable in the frontend paste functions,
passed directly to term_do_paste which now takes (buffer,length)
parameters, and freed immediately afterwards. get_clip() is gone.
This commit is contained in:
Simon Tatham
2017-12-09 08:41:03 +00:00
parent c05fdb7d61
commit f26654f618
5 changed files with 73 additions and 102 deletions

View File

@ -6073,66 +6073,66 @@ static void term_paste_callback(void *vterm)
term->paste_len = 0;
}
void term_do_paste(Terminal *term)
void term_do_paste(Terminal *term, const wchar_t *data, int len)
{
wchar_t *data;
int len;
const wchar_t *p, *q;
get_clip(term->frontend, &data, &len);
if (data && len > 0) {
wchar_t *p, *q;
/*
* Pasting data into the terminal counts as a keyboard event (for
* purposes of the 'Reset scrollback on keypress' config option),
* unless the paste is zero-length.
*/
if (len == 0)
return;
term_seen_key_event(term);
term_seen_key_event(term); /* pasted data counts */
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_pos = term->paste_len = 0;
term->paste_buffer = snewn(len + 12, wchar_t);
if (term->bracketed_paste) {
memcpy(term->paste_buffer, L"\033[200~", 6 * sizeof(wchar_t));
term->paste_len += 6;
}
p = q = data;
while (p < data + len) {
while (p < data + len &&
!(p <= data + len - sel_nl_sz &&
!memcmp(p, sel_nl, sizeof(sel_nl))))
p++;
{
int i;
for (i = 0; i < p - q; i++) {
term->paste_buffer[term->paste_len++] = q[i];
}
}
if (p <= data + len - sel_nl_sz &&
!memcmp(p, sel_nl, sizeof(sel_nl))) {
term->paste_buffer[term->paste_len++] = '\015';
p += sel_nl_sz;
}
q = p;
}
if (term->bracketed_paste) {
memcpy(term->paste_buffer + term->paste_len,
L"\033[201~", 6 * sizeof(wchar_t));
term->paste_len += 6;
}
/* Assume a small paste will be OK in one go. */
if (term->paste_len < 256) {
if (term->ldisc)
luni_send(term->ldisc, term->paste_buffer, term->paste_len, 0);
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_buffer = 0;
term->paste_pos = term->paste_len = 0;
term->paste_buffer = snewn(len + 12, wchar_t);
if (term->bracketed_paste) {
memcpy(term->paste_buffer, L"\033[200~", 6 * sizeof(wchar_t));
term->paste_len += 6;
}
p = q = data;
while (p < data + len) {
while (p < data + len &&
!(p <= data + len - sel_nl_sz &&
!memcmp(p, sel_nl, sizeof(sel_nl))))
p++;
{
int i;
for (i = 0; i < p - q; i++) {
term->paste_buffer[term->paste_len++] = q[i];
}
}
if (p <= data + len - sel_nl_sz &&
!memcmp(p, sel_nl, sizeof(sel_nl))) {
term->paste_buffer[term->paste_len++] = '\015';
p += sel_nl_sz;
}
q = p;
}
if (term->bracketed_paste) {
memcpy(term->paste_buffer + term->paste_len,
L"\033[201~", 6 * sizeof(wchar_t));
term->paste_len += 6;
}
/* Assume a small paste will be OK in one go. */
if (term->paste_len < 256) {
if (term->ldisc)
luni_send(term->ldisc, term->paste_buffer, term->paste_len, 0);
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_buffer = 0;
term->paste_pos = term->paste_len = 0;
}
}
get_clip(term->frontend, NULL, NULL);
queue_toplevel_callback(term_paste_callback, term);
}