Skip to content

Fix crashes from stale text positions - #80

Open
whitneyland wants to merge 1 commit into
gonzalezreal:mainfrom
whitneyland:fix-stale-text-selection
Open

Fix crashes from stale text positions#80
whitneyland wants to merge 1 commit into
gonzalezreal:mainfrom
whitneyland:fix-stale-text-selection

Conversation

@whitneyland

@whitneyland whitneyland commented Jul 30, 2026

Copy link
Copy Markdown

Summary

  • Validate text positions before indexing resolved layouts.
  • Return nil or a neutral offset when UIKit asks about positions retained across a layout reset.
  • Add regression coverage for a non-empty layout becoming empty.

Why

UIKit can retain UITextPosition values while SwiftUI replaces Textual's layout collection. If the new collection is empty, offset(from:to:) currently indexes layouts[0] and traps. Treating those positions as invalid lets UIKit discard the stale query safely.

Testing

  • make test-ios — 161 tests passed.
  • make test-macos — 139 tests passed.
  • Built a downstream iOS app against the local package branch.

Fixes #72

AI tooling assisted with crash analysis and implementation. I reviewed the changes and test results.

@whitneyland

Copy link
Copy Markdown
Author

Hi, if you have any questions I'm glad to discuss further. Great work on the project, it's really impressive.

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.

Text selection in StructuredText doesn't work with navigation

1 participant