Skip to content

Tell the app when the selection changes - #18

Merged
servercimen merged 1 commit into
feature/turn-off-selectionfrom
feature/selection-change
Nov 20, 2026
Merged

servercimen merged 1 commit into
feature/turn-off-selectionfrom
feature/selection-change

Conversation

@servercimen

@servercimen servercimen commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

An app could set the selection with select(_:) and read selectedText, but it could not find out when the person changed or ended a selection.

  • TranscriptTextView.selectedRange: the selection in the document's flat UTF-16 offset space, or nil.
  • TranscriptTextView.onSelectionChange: called on the main thread after each change, with nil when nothing is selected any more.
  • TranscriptTextView.selectsAllWhenShown: selects all of the text, with the selection handles shown, once the view is in a window and has text.
  • TranscriptText has .onSelectionChange(_:) and .selectsAllWhenShown(_:).
  • The README has a "Reading the selection" section.

Closes #6.

Stack

This PR is part of a stack. It is based on #17 (feature/turn-off-selection), so its diff shows only this change. Merge the stack in order, starting with #17.

Tests

  • The package builds for iOS. The change is iOS-only, and swift test passes with it in the stack.
  • Checked on an iPhone 12 mini, iOS 27.0. With .selectsAllWhenShown(), the view became first responder with selectedRange 0..<48 and the whole text in selectedText. select(nil) cleared it, and onSelectionChange reported 0..<48, then nil.

🤖 Generated with Claude Code

An app could set the selection with select(_:) and read selectedText, but
it could not find out when the person changed or ended a selection.

TranscriptTextView now has selectedRange and onSelectionChange, which is
called on the main thread after each change, with nil when nothing is
selected any more. selectsAllWhenShown selects all of the text, with the
selection handles shown, once the view is in a window and has text.
TranscriptText has .onSelectionChange(_:) and .selectsAllWhenShown(_:).

Closes #6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tell the app when the selection changes

1 participant