Comment 7 for bug 1926256

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

This is not an issue with the terminals, this is a new feature of bash-5.1. Search for the word "highlight" at https://lists.gnu.org/archive/html/info-gnu/2020-12/msg00003.html .

---

This could not theoretically be a bug in gnome-terminal/vte. Terminals don't directly paint a letter as a consequence of the user pressing that letter, or pasting something.

I'm certain you can think of plenty of cases where pressing a certain letter does not cause that letter to be painted on the canvas, but some other action (larger repaints), or perhaps nothing at all.

When you press a letter, or paste some text, it is forwarded towards the kernel over the tty line, but is not displayed. The kernel then might handle it itself, or forward further towards some application (e.g. bash in this case).

Then that application may or may not decide to paint something. Whatever it decides to paint may or may not be the same as the typed letter or pasted text. But even if it's the same, the terminal has no way of making this connection. "The user pressed the letter X, I've forwarded it, 100 milliseconds later I received a letter X to be painted, it must be the «same» X" -- it cannot work like this.

What happens in this particular case is that you paste "foo", and in response bash instructs the terminal to print "foo" in inverse colors. The terminal does what it must do: obeys this instuction (without having the slightest idea that it's related to the paste).

---

Two more things to mention to complete the picture:

There is a so-called "bracketed paste mode", where special markers are inserted at the beginning and end of pasted data. This is how applications (bash in this case) can distinguish it from data typed by the user, without relying on timing heuristics.

Also, some terminals have a legacy "local echo" mode where pressed keys immediately appear on the screen. I'm fairly certain it's not used anywhere nowadays. Most terminals don't support it, and VTE removed it in version 0.60, see https://gitlab.gnome.org/GNOME/vte/-/issues/69 .