Properly encode pasted text containing newlines #2248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #1959.
I received a report in my project (akinomyoga/ble.sh#544).
The problem is that Tilix currently sends the raw text to the terminal application with its advanced paste dialog. However, the data sent to the terminal application is not plain text but should properly be encoded following the convention of the terminal communication. In particular, the newlines should be encoded by
\x0D
(which has an equivalent byte representation as CR\r
in an ASCII string) in the traditional terminal protocol because\x0A
(which has the same byte representation as LF\n
in an ASCII string) means C-j in the convention. Actually,\x0D
is technically C-m, but it is traditionally used as a synonym of RET. If one wants to send the multiline text preserving the variations of newlines, when the terminal application requests the bracketed paste mode, the terminal should use the bracketed-paste-mode beginning/ending markers of the pasted text. All this processing is supposed to be handled by VTE'svte_terminal_paste_text
, but Tilix currently usesvte_terminal_feed_child
to directly send the raw pasted text.The same problem has been reported in #1959 for nano.
Ideally, we should use
vte_terminal_paste_text
through GtkD'sTerminal::pasteText
. However, this interface of GtkD has not yet been released. In this PR, we instead convert the newlines manually. I have confirmed that both issues #1959 and akinomyoga/ble.sh#544 are fixed with this change.