Repository navigation
Copy rich text, and set up the text interaction before a selection from code - #42
Merged
Merged
Conversation
selectsAllWhenShown called becomeFirstResponder() before the UITextInteraction existed. The interaction then did not show the selection handles for the selection that came next. becomeFirstResponder() now adds the interaction first. This covers selectsAllWhenShown and an app that calls becomeFirstResponder() itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy wrote only plain text. A paste into a rich-text editor lost the fonts, bold, italic and links. Copy now writes one pasteboard item with two types. The plain text is the same text as before. The RTF has the same characters, with the fonts of the style, links, strikethrough and underline, and no colors. copyText(in:) and the rich text use one walker, so both always have the same text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RTF has the list markers, quote prefixes, tables and rules of the plain text as characters, not as RTF lists or tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rich copy tests used NSUnderlineStyle with only AppKit imported, so the test target did not build for iOS. The file now imports UIKit where it can, as RichCopy.swift does. The tests now also check underline, and they check that strikethrough and underline stay when the RTF is read back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rich copy of a table was the plain Markdown table in the block font. Bold, italic, code and links in the cells were lost. Each cell is now styled from its spans, and the pipes and the separator row go between the cells. The plain text does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The list and quote prefixes went in with one insert per line, from the last line to the first. Each insert moved the rest of the text, so a long code block in a list item or a quote took time in proportion to its lines times its length. The copy now appends each prefix and line to a new string, so the time is linear. The text does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comment said that the interaction shows the selection only if it is in place when the view becomes first responder. A check on iOS 27.0 showed the handles also when the view became first responder before the interaction existed. The code still adds the interaction first, so the view is never first responder without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RTF named the system font by its private names, for example .SFUI-Semibold. An app that finds a font by its name in the RTF does not find these names, and shows another font, such as Times. Copy now changes each font with a private name to Helvetica Neue with the same size, bold and italic, or to Menlo for monospaced text. Fonts that the app sets by name do not change. A UIKit reader that knew the system font now gets Helvetica Neue in its place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some apps find the system font by its private name, and some do not. The doc comment and the README now say that some apps do not find it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the code font was the monospaced system font, the copy changed it to Menlo-Regular before it read the bold and italic traits, so code in bold or italic lost them in a paste. Now the copy picks Menlo and then applies the traits, as it does for the other text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptTextView.copy(_:): the copy runs on the main thread from any thread, copies selectedRange, and puts plain and rich text on the pasteboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 12 of a stack of 13 pull requests. The base is #41 (
feature/replace-transition). #31 (part 1) tells how to merge the stack.On this stacked branch,
swift testpasses (386 tests), and the iOS build and build-for-testing pass.Summary
Copy put only plain text on the pasteboard. A paste into a rich text editor then lost the headings, bold, italic, code and links. Also,
selectsAllWhenShown, or an app that callsbecomeFirstResponder()itself, made the view first responder before its text interaction existed.copy(_:)writes one pasteboard item with two types.public.utf8-plain-textis the same text as before (copyText(in:)).public.rtfhas the same characters, with the fonts of the style for headings, bold, italic, inline code and code blocks, and with links, strikethrough and underline. Text in table cells keeps its bold, italic, code and links. The RTF has no colors, so pasted text takes the colors of the place it goes to.becomeFirstResponder()adds theUITextInteractionbefore the view becomes first responder.UITextViewdoes.Tests
swift teston macOS: 186 tests pass. The tests inRichCopyTests.swiftcheck that the rich text has the characters ofcopyText(in:), and check the fonts, links, strikethrough, underline, partial spans and table cells. They read the RTF back, and check that each font has a public name. A test for the last commit checks bold and italic code in the monospaced system font. It failed before that commit.xcodebuild build -scheme TranscriptKit -destination 'generic/platform=iOS'at the last commit: the build succeeds with no warnings.Checked on an iPhone 12 mini
iOS 27.0, in a check screen in a local test app. The phone check ran on the commit before the last one. The first runs were on main. Main showed the rich copy problem. Look Up, the selection rule and the handles behaved the same on main.
public.utf8-plain-text, and a paste into a rich text view is plain text in one font. The branch writes both types in one item, and the plain text equalscopyText(in:). A paste keeps the 25.5 pt bold heading, bold, italic, monospaced code and the link. The RTF names only public fonts: Helvetica Neue faces, Menlo, and Avenir for a style that names it.selectsAllWhenShown: on main, the view becomes first responder without a text interaction, but the handles still show in all 5 variants (UIKit before and after the window, SwiftUI, a stream, a sheet). So the phone did not show that the change is necessary. The branch shows the same handles.Stand-ins: the menus open with
UIMenuController.showMenu, and Copy, Share and Translate go to the first responder withUIApplication.sendAction. The check reads the visible handles fromUITextSelectionDisplayInteraction, and screenshots confirm them. The paste goes into an editableUITextViewin the test app.Not checked
🤖 Generated with Claude Code