Strip NULs from bracketed paste text as a Windows workaround

See #1661 for lots of context. Long story short, in Windows Terminal it
looks like any character that would requite the press of a modifier key
causes a NUL to appear in the pasted text for that character. This feels
like it could be a bug in Windows Terminal and we will investigate and
report at some point.

Meanwhile though this provides a workaround that has the paste experience
work the same as I'm seeing on macOS (and I would imagine in most terminals
on GNU/Linux too).
This commit is contained in:
Dave Pearson
2023-01-25 14:24:37 +00:00
parent 7bdc8f9c7a
commit 32bb79362c

View File

@@ -118,7 +118,10 @@ class XTermParser(Parser[events.Event]):
# ESC from the closing bracket, since at that point we didn't know what
# the full escape code was.
pasted_text = "".join(paste_buffer[:-1])
on_token(events.Paste(self.sender, text=pasted_text))
# Note the removal of NUL characters: https://github.com/Textualize/textual/issues/1661
on_token(
events.Paste(self.sender, text=pasted_text.replace("\x000", ""))
)
paste_buffer.clear()
character = ESC if use_prior_escape else (yield read1())