From 32bb79362c29714e4b351000de153e8b175dbf62 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 25 Jan 2023 14:24:37 +0000 Subject: [PATCH 1/3] 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). --- src/textual/_xterm_parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 1bbec555d6..7e1e719a23 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -118,7 +118,10 @@ def reissue_sequence_as_keys(reissue_sequence: str) -> None: # 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()) From 8145c08007f0a090f11bd9f9cbd5c2df84a83591 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 25 Jan 2023 14:30:56 +0000 Subject: [PATCH 2/3] Update the CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df3fadf4f2..40d10bbdb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed relative units in `grid-rows` and `grid-columns` being computed with respect to the wrong dimension https://github.com/Textualize/textual/issues/1406 - Programmatically setting `overflow_x`/`overflow_y` refreshes the layout correctly https://github.com/Textualize/textual/issues/1616 - Fixed double-paste into `Input` https://github.com/Textualize/textual/issues/1657 +- Added a workaround for an apparent Windows Terminal paste issue https://github.com/Textualize/textual/issues/1661 ## [0.10.1] - 2023-01-20 From 44d48e244ef840bf327f4b0d8876e1ff6fcdd59c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 25 Jan 2023 14:43:41 +0000 Subject: [PATCH 3/3] Fix typo in replace AKA: don't mix octal and hex Dave! --- src/textual/_xterm_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 7e1e719a23..b97a1abd1b 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -120,7 +120,7 @@ def reissue_sequence_as_keys(reissue_sequence: str) -> None: pasted_text = "".join(paste_buffer[:-1]) # Note the removal of NUL characters: https://github.com/Textualize/textual/issues/1661 on_token( - events.Paste(self.sender, text=pasted_text.replace("\x000", "")) + events.Paste(self.sender, text=pasted_text.replace("\x00", "")) ) paste_buffer.clear()