Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(swift-ios): enable granular text selection #6110

Mergedsaphid(GitHub profile, opens in a new tab)merged 3 commits intot3code/rebuild-mobile-app-swift fromrefs/pull/6110/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

What Changed

  • render Markdown paragraphs, headings, lists, tables, and code blocks with selectable native text
  • preserve bold, italic, inline-code, strike-through, link, and Dynamic Type styling
  • keep selections stable while a streaming response appends text
  • retain code-block wrapping/copy controls and route link actions through SwiftUI openURL
  • add focused coverage for formatting, Dynamic Type, code reuse, and selection restoration

Why

The native SwiftUI thread view only offered whole-message copying. People could not select a word, sentence, or code fragment with standard iOS selection handles.

This adds granular native selection while keeping message-level copy actions, streaming updates, accessibility actions, safe link routing, and the existing Markdown layout behavior.

Closes #6089.

UI Changes

Long-pressing rendered assistant prose or code now shows the native iOS selection handles and edit menu (Copy, Look Up, Translate). The appearance of messages is otherwise unchanged.

Verified in the iOS Simulator inside a live thread: native selection appeared on prose and the existing code-block controls remained available. A physical-phone acceptance pass will be attached after the approved-based combined build is installed.

Verification

  • MarkdownDocumentTests: 15 passed, 0 failed on iOS Simulator
  • combined simulator pass with PR #6090: native selection menu appeared and full-surface back swipe returned to the thread list
  • git diff --check: passed
  • fresh direct Claude Opus 5 high review of the final diff: exit 0, no actionable findings

Checklist

  • This PR is focused on one native behavior
  • I explained what changed and why
  • Before/after screenshots are not applicable because message appearance is unchanged
  • I included a video for the interaction change

Implemented with GPT-5.6 Sol in T3 Code/Codex. Independently reviewed by Claude Opus 5 high.

Note

Enable granular text selection in markdown messages using UITextView

  • Replaces SwiftUI Text-based inline rendering with a UIViewRepresentable wrapping UITextView (MarkdownInlineText), enabling native per-word/character text selection without a toggle.
  • Adds MarkdownSelectableTextAttributes to centrally build NSAttributedString from inline markdown runs, applying dynamic type, link handling, inline code monospacing, and strikethrough.
  • Adds MarkdownSelectionRestoration to preserve the user's selection range across streaming updates when the new text safely extends the previous text.
  • Propagates selectionContext and textColor through MarkdownBlocksView, MarkdownBlockView, MarkdownTableView, MarkdownListView, and MarkdownCodeBlockView so all message content is selectable.
  • Adds a configurable copyActionTitle to MarkdownMessageView, used in both the accessibility action and the UITextView edit menu; file previews use "Copy file contents".
  • Behavioral Change: the old MarkdownTextSelectionModifier toggle is removed; text selection is always active via UIKit.
Macroscope summarized 2ae671d.

Note

Medium Risk Large UIKit bridge in the hot-path transcript with streaming selection and layout sizing; behavior changes for table cell accessibility and keyboard dismissal on scroll.

Overview Chat markdown now renders inline content through UITextView-backed views instead of SwiftUI Text, so users get native selection handles and the system edit menu across paragraphs, headings, lists, tables, and code bodies.

A MarkdownSelectionContext carries the full message (or file) text and a configurable copy title into each text view; the delegate adds Copy message / Copy file contents to the selection menu and keeps message-level copy via accessibility actions. MarkdownSelectionRestoration preserves the selected range while streaming only when new text extends the previous string.

Rendering moves inline styling to MarkdownSelectableTextAttributes and MarkdownInlineStyle.uiFont (Dynamic Type), adds shared UIKit theme colors for text views, and pre-renders code blocks as literal .code inline runs (reused from cache). The old context-menu “Select text” toggle is removed.

Transcript scrolling no longer calls endEditing on drag; keyboard dismissal goes through the existing onDismissKeyboard path. Tests cover formatting, Dynamic Type, code reuse, and selection restoration; home metadata tests switch to providersByEnvironment fixtures.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2ae671d8076c31af7fa226d65a756559b486db0a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Delivery: direct Validated against Theo commit: f98cab553546558e28d6e22f3dbe9807ecc3325f Depends on: none Merge order: this PR only Validation status: Mergeable; native/repository checks and current review are green. The unrelated Vercel authorization failure is a maintainer-side gate.

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 23359412-8d23-42e6-b18b-d793f74c16fb

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Phone acceptance update: Alex confirmed that text selection is working on the physical phone. This PR is ready for maintainer review. The stale provider-catalog native test fixture is fixed in #6130, and this branch carries the same focused test repair; the current SwiftUI native check is green.

    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2ae671d8076c31af7fa226d65a756559b486db0a. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -191,14 +210,20 @@
      191210 }
      192211 }
      193212
      194213 private struct MarkdownBlocksView: View {
      195214 let blocks: [MarkdownRenderedBlock]
      215+ let selectionContext: MarkdownSelectionContext
      196216 var spacing: CGFloat = 12
      217+ var textColor: MarkdownTextColor = .primary
      197218
      198219 var body: some View {
      199220 VStack(alignment: .leading, spacing: spacing) {
      200221 ForEach(blocks.indices, id: \.self) { index in
      201222 // Unchanged blocks share inline runs by reference across
      202223 // streaming revisions, so equatable comparison skips their
      203224 // body and layout entirely; only the changed tail re-renders.
      204- MarkdownBlockView(block: blocks[index])
      225+ MarkdownBlockView(
      226+ block: blocks[index],
      227+ selectionContext: selectionContext,
      228+ textColor: textColor
      229+ )

      Dynamic Type updates get skipped

      Medium Severity

      MarkdownInlineText now bakes fonts from @Environment(\.dynamicTypeSize), but its parent MarkdownBlockView still uses .equatable() and only compares block, selectionContext, and textColor. When Dynamic Type changes alone, equality stays true, so body is skipped and selectable text keeps the old size. This is a regression from the previous Text + text-style Font path, which scaled without an environment read. File previews have no cell reconfigure workaround.

      Additional Locations (2)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2ae671d8076c31af7fa226d65a756559b486db0a. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Approvability

      Verdict: Needs human review

      This PR introduces a new granular text selection feature with significant new UIKit bridging code and selection state management (~700 lines). An unresolved review comment also identifies a potential Dynamic Type accessibility regression. Human review is recommended for this new capability.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. one blocking Dynamic Type regression remains.

      @@ -192,14 +211,20 @@
      192211 }
      193212
      194213 private struct MarkdownBlocksView: View {
      195214 let blocks: [MarkdownRenderedBlock]
      215+ let selectionContext: MarkdownSelectionContext
      196216 var spacing: CGFloat = 12
      217+ var textColor: MarkdownTextColor = .primary
      197218
      198219 var body: some View {
      199220 VStack(alignment: .leading, spacing: spacing) {
      200221 ForEach(blocks.indices, id: \.self) { index in
      201222 // Unchanged blocks share inline runs by reference across
      202223 // streaming revisions, so equatable comparison skips their
      203224 // body and layout entirely; only the changed tail re-renders.
      204- MarkdownBlockView(block: blocks[index])
      225+ MarkdownBlockView(
      226+ block: blocks[index],
      227+ selectionContext: selectionContext,
      228+ textColor: textColor
      229+ )
      205230 .equatable()

      MarkdownInlineText now derives UIKit fonts from dynamicTypeSize, but this equatable boundary does not include that environment value. a Dynamic Type-only change can skip rebuilding unchanged blocks, leaving selectable text at the old size. include the size/category in the equatable inputs or remove this equality optimization for these blocks.

    7. t3-code-bot[bot](GitHub profile, opens in a new tab) approved these changes

      correction after independent review: the prior Dynamic Type concern is not blocking. the UIKit representable directly reads dynamicTypeSize, includes it in its attributed-text cache key, and has focused scaling coverage. selection remains block-scoped and the many-UITextView layout cost is worth monitoring, but neither is a correctness blocker for this PR. approved.

Sign in to join this conversation.