diff options
author | erw7 <erw7.github@gmail.com> | 2020-04-02 20:21:49 +0900 |
---|---|---|
committer | erw7 <erw7.github@gmail.com> | 2021-02-04 15:20:05 +0900 |
commit | 14158e8d4722bf96614e5b51bd098dd77422c7c5 (patch) | |
tree | c6d306204493ef90065a827fe4e0e7354211e65d | |
parent | 81a30f436769bd891be25ef9bd5f6543863a9d62 (diff) | |
download | rneovim-14158e8d4722bf96614e5b51bd098dd77422c7c5.tar.gz rneovim-14158e8d4722bf96614e5b51bd098dd77422c7c5.tar.bz2 rneovim-14158e8d4722bf96614e5b51bd098dd77422c7c5.zip |
Change to filter control characters when pasting a terminal window
Change to filter the following control characters in the same way as
xterm.
\x00-\x07, \x0b-\x0c, \x0e-\x1f
-rw-r--r-- | src/nvim/terminal.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index e1c940f77a..6249c8eac5 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -539,6 +539,8 @@ void terminal_paste(long count, char_u **y_array, size_t y_size) { vterm_keyboard_start_paste(curbuf->terminal->vt); terminal_flush_output(curbuf->terminal); + size_t buff_len = STRLEN(y_array[0]); + char_u *buff = xmalloc(buff_len); for (int i = 0; i < count; i++) { // -V756 // feed the lines to the terminal for (size_t j = 0; j < y_size; j++) { @@ -546,9 +548,24 @@ void terminal_paste(long count, char_u **y_array, size_t y_size) // terminate the previous line terminal_send(curbuf->terminal, "\n", 1); } - terminal_send(curbuf->terminal, (char *)y_array[j], STRLEN(y_array[j])); + size_t len = STRLEN(y_array[j]); + if (len > buff_len) { + buff = xrealloc(buff, len); + buff_len = len; + } + char_u *p = buff; + char_u *q = y_array[j]; + while (*q != '\0') { + if ((*q > '\x07' && *q < '\x0e' && *q != '\x0b' && *q != '\x0c') + || *q > '\x1f') { + *(p++) = *q; + } + q++; + } + terminal_send(curbuf->terminal, (char *)buff, (size_t)(p - buff)); } } + xfree(buff); vterm_keyboard_end_paste(curbuf->terminal->vt); terminal_flush_output(curbuf->terminal); } |