Only treat runs of "?" as lost plain text when pasting
Summary
Pasting ordinary text that had two ? anywhere in it (two questions in a chat message, two URLs with query strings) and also carried an HTML or RTF flavor was treated as possibly lossy. The paste then skipped the plain-text fast path and parsed the rich-text flavor. In 0.64.20 that parse ran the WebKit HTML importer on the main thread and froze the UI (#9998). Current main already parses HTML with XMLDocument and prepares pastes in a worker, but the same check still sends these pastes to the full paste worker instead of the lightweight one added in #14121.
The check exists for #2818-style loss, where an exporter replaces each character it cannot encode (Cyrillic, CJK) with ?. A lost word is therefore a run of ?. shouldInspectRichTextForPlainTextLoss now looks for U+FFFD or two consecutive ? instead of counting ? across the whole string. The plain-text paste helper (workers/cmux-paste-text/main.m) mirrors the same rule.
What still takes the rich path: ??~, ?????? ???, any U+FFFD, and a literal ?? in prose (the comparison then keeps the plain text, as before). What no longer does: isolated ?, however many. A single lost character on its own (a ? b) was not caught reliably before either and is still not.
Still on the slow path: text with a literal ??, which includes code using the nil-coalescing operator (Swift, TS, C#, Kotlin). Gating on the flavor instead would break #3910, where an editor writes the lossy text into the UTF-8 flavor itself. On current main that path parses HTML with XMLDocument in the paste worker, so it costs latency, not a frozen UI.
Fixes #9998
Testing
python3 tests/test_plain_text_paste_worker.pywith the helper built byscripts/build-plain-text-paste-worker.sh: 12 tests pass locally (macOS 26.6). The fast-path test now includesWhy? Why not?and two query-string URLs next to HTML/RTF flavors; the lossy cases (??,日本語??, U+FFFD) still delegate.PasteboardTextFidelityTestsgains isolated-?cases (questions, URLs, a 1,000-question paste) and run cases. Those run in CI; I checked the function logic locally with a standalone script, not the package build.
Checklist
- Behavior changes have added or updated tests, or Testing says why not
🤖 Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes the paste path so plain text with two ? characters (two chat questions, URLs with query strings) no longer goes through rich-text parsing. Previously, any two ? anywhere in the plain-text flavor counted as possible exporter loss; only U+FFFD replacement characters or a run of two consecutive ? (the signature of an exporter dropping unencodable characters) trigger the rich path now.
Both shouldInspectRichTextForPlainTextLoss and the cmux-paste-text worker mirror the run-of-?/U+FFFD rule. New tests cover isolated ? in questions, query-string URLs, and a 1,000-question paste to keep them on the fast path. A literal ?? in prose still takes the rich path, with the fidelity comparison keeping the plain text as before.
Bug Fixes
- Isolated
?no longer counts as possible exporter loss, avoiding the full paste worker (#9998). - U+FFFD or consecutive
?still route to the rich-text path for loss recovery. - Added tests for questions, query-string URLs, and a 1,000-question paste.
Summary by CodeRabbit
- Bug Fixes
- Improved detection of potentially corrupted plain text when rich-text content is available. Replacement characters and consecutive question marks are flagged, while separated question marks in prose, URLs, and shell commands no longer trigger the check.