From d284b6a3924d93a38a51903e417d76336be5a504 Mon Sep 17 00:00:00 2001 From: Austin Wang <38676809+austinywang@users.noreply.github.com> Date: Wed, 23 Sep 2026 20:05:00 -0700 Subject: [PATCH 1/5] test: cover fast paste for mixed plain and HTML clipboard --- tests/test_plain_text_paste_worker.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_plain_text_paste_worker.py b/tests/test_plain_text_paste_worker.py index 2e88c0d5e9ff..611e30de34c2 100644 --- a/tests/test_plain_text_paste_worker.py +++ b/tests/test_plain_text_paste_worker.py @@ -92,6 +92,13 @@ def test_unicode_multiline_and_repeat(self): print(json.dumps(dict(helper_startup_ms=ms, directory=directory_index, repetition=repetition, size=Path(HELPER).stat().st_size)), flush=True) + def test_plain_text_with_html_uses_fast_path(self): + text = "hello\n日本語 🦀\n" + board = self.board(text=text, extra={"public.html": "
rich
"}) + result = self.result(self.directory(board)) + self.assertEqual(result["textPayload"]["destination"], {"terminal": {}}) + self.assertEqual((self.workdirs[-1] / "text-payload.txt").read_bytes(), text.encode()) + def test_rich_images_and_auxiliary_urls_delegate_without_provider_read(self): for flavor in ["public.html", "public.rtf", "com.apple.flat-rtfd", "public.png", "public.tiff", "public.jpeg", "public.file-url", "public.url", From a9c54baa8e34d2a1d52c3cc525938e61b173d6c9 Mon Sep 17 00:00:00 2001 From: Austin Wang <38676809+austinywang@users.noreply.github.com> Date: Wed, 23 Sep 2026 20:05:19 -0700 Subject: [PATCH 2/5] fix: keep mixed rich text paste on the fast plain-text path --- workers/cmux-paste-text/main.m | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/workers/cmux-paste-text/main.m b/workers/cmux-paste-text/main.m index b01dfb315c36..af4f5a5d1478 100644 --- a/workers/cmux-paste-text/main.m +++ b/workers/cmux-paste-text/main.m @@ -121,10 +121,7 @@ static BOOL isPlainTextType(NSString *typeIdentifier) { } static BOOL hasDisallowedType(NSString *typeIdentifier) { - if ([typeIdentifier isEqualToString:NSPasteboardTypeHTML] || - [typeIdentifier isEqualToString:NSPasteboardTypeRTF] || - [typeIdentifier isEqualToString:NSPasteboardTypeRTFD] || - [typeIdentifier isEqualToString:NSPasteboardTypeFileURL] || + if ([typeIdentifier isEqualToString:NSPasteboardTypeFileURL] || [typeIdentifier isEqualToString:NSPasteboardTypeURL] || [typeIdentifier isEqualToString:@"NSFilenamesPboardType"] || [typeIdentifier isEqualToString:@"com.apple.pasteboard.promised-file-url"] || @@ -190,13 +187,12 @@ static int runWorker(NSArrayrich
"}) - result = self.result(self.directory(board)) - self.assertEqual(result["textPayload"]["destination"], {"terminal": {}}) - self.assertEqual((self.workdirs[-1] / "text-payload.txt").read_bytes(), text.encode()) + def test_plain_text_with_rich_flavors_uses_fast_path(self): + for flavor in ["public.html", "public.rtf"]: + for text in ["hello\n日本語 🦀 e\u0301\r\n", "Question?", "文本\n" * 100_000]: + with self.subTest(flavor=flavor, bytes=len(text.encode())): + board = self.board(text=text, extra={flavor: "unused rich text"}) + path = self.directory(board) + result = self.result(path) + self.assertEqual(result["textPayload"]["destination"], {"terminal": {}}) + self.assertEqual((path / "text-payload.txt").read_bytes(), text.encode()) + + def test_rich_only_and_empty_plain_text_delegate(self): + for flavor in ["public.html", "public.rtf", "com.apple.flat-rtfd"]: + for text in [None, ""]: + with self.subTest(flavor=flavor, text=text): + board = self.board(text=text, extra={flavor: "rich fallback"}) + self.result(self.directory(board), expected=73) + + def test_lossy_plain_text_with_rich_flavors_delegates(self): + for flavor in ["public.html", "public.rtf"]: + for text in ["??", "text\ufffd", "日本語??"]: + with self.subTest(flavor=flavor, text=text): + board = self.board(text=text, extra={flavor: "rich fallback"}) + self.result(self.directory(board), expected=73) + + def test_loss_markers_without_rich_text_remain_literal(self): + text = "??\ufffd" + board = self.board(text=text) + path = self.directory(board) + self.result(path) + self.assertEqual((path / "text-payload.txt").read_bytes(), text.encode()) def test_rich_images_and_auxiliary_urls_delegate_without_provider_read(self): - for flavor in ["public.html", "public.rtf", "com.apple.flat-rtfd", "public.png", + for flavor in ["com.apple.flat-rtfd", "public.png", "public.tiff", "public.jpeg", "public.file-url", "public.url", "NSFilenamesPboardType", "com.apple.pasteboard.promised-file-url"]: with self.subTest(flavor=flavor): From f3f43ed7d470801f99827f2c49ae7f2288e9f01a Mon Sep 17 00:00:00 2001 From: Austin Wang <38676809+austinywang@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:42:51 -0700 Subject: [PATCH 4/5] fix: retain rich text fallback for lossy paste data --- workers/cmux-paste-text/main.m | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/workers/cmux-paste-text/main.m b/workers/cmux-paste-text/main.m index af4f5a5d1478..d08105a4ce7b 100644 --- a/workers/cmux-paste-text/main.m +++ b/workers/cmux-paste-text/main.m @@ -121,6 +121,8 @@ static BOOL isPlainTextType(NSString *typeIdentifier) { } static BOOL hasDisallowedType(NSString *typeIdentifier) { + // RTFD may carry attachments even alongside plain text. Keep its existing + // rich-text/image selection policy in the full worker. if ([typeIdentifier isEqualToString:NSPasteboardTypeFileURL] || [typeIdentifier isEqualToString:NSPasteboardTypeURL] || [typeIdentifier isEqualToString:@"NSFilenamesPboardType"] || @@ -187,12 +189,16 @@ static int runWorker(NSArray