Skip to content

Conversation

@JonET
Copy link
Contributor

@JonET JonET commented Jul 27, 2025

The app would crash with 'attempt to create backwards NSTextRange from 1 to 0' when pasting images into a post. This was caused by the text system trying to query text ranges while they were being modified.

Fixed by:

  • Storing the original selected range before text storage modifications
  • Completing all text storage edits before updating the selection
  • Deferring selection updates to the next run loop cycle to avoid conflicts with the text system's internal state
  • Adding bounds checking to ensure valid cursor positions

This prevents race conditions between our selection updates and the text system's attribute queries.

The app would crash with 'attempt to create backwards NSTextRange from 1 to 0' when pasting images into a post. This was caused by the text system trying to query text ranges while they were being modified.

Fixed by:
- Storing the original selected range before text storage modifications
- Completing all text storage edits before updating the selection
- Deferring selection updates to the next run loop cycle to avoid conflicts with the text system's internal state
- Adding bounds checking to ensure valid cursor positions

This prevents race conditions between our selection updates and the text system's attribute queries.
@JonET JonET requested review from dfsm and nolanw July 27, 2025 22:58
Copy link
Member

@nolanw nolanw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@JonET JonET merged commit ff6c880 into main Jul 28, 2025
1 check passed
@JonET JonET deleted the fix-image-paste-crash branch July 28, 2025 01:48
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.

3 participants