Skip to content

fix(ios): use controlled path for Cut to prevent formatting corruption#278

Merged
hryhoriiK97 merged 3 commits intomainfrom
fix/ios-cut-formatting-corruption
Apr 29, 2026
Merged

fix(ios): use controlled path for Cut to prevent formatting corruption#278
hryhoriiK97 merged 3 commits intomainfrom
fix/ios-cut-formatting-corruption

Conversation

@hryhoriiK97
Copy link
Copy Markdown
Collaborator

@hryhoriiK97 hryhoriiK97 commented Apr 29, 2026

What/Why?

Fixes: #273

Using "Cut" on a mixed selection produces deformed markdown. Cut was routing through UIKit's standard delegate chain (replaceRange:withText:), which is subject to the same timing races. On slower devices or in low power mode, the formatting store gets misaligned because the delegate-based edit parameter inference uses stale values.

Testing

PR Checklist

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes

Always update _lastSelectedRange in textViewDidChangeSelection and
textInputDidChangeSelection before the isApplyingFormatting guard,
ensuring _preEditSelectedRange is never stale when handleTextChanged
computes edit parameters. Also clamp modificationRange passed to the
detector pipeline so out-of-bounds values cannot reach ENRMWordsUtils.

Made-with: Cursor
Route Cut through replaceSelectedTextWith:formattingRanges: instead of
UIKit's replaceRange:withText: (iOS) / insertText:replacementRange:
(macOS). The controlled path bypasses the delegate chain and calls
adjustForEditAtLocation: with exact parameters, eliminating timing
races that corrupt the formatting store on slower devices or low
power mode.

Made-with: Cursor
@hryhoriiK97 hryhoriiK97 merged commit fa81a11 into main Apr 29, 2026
5 checks passed
@hryhoriiK97 hryhoriiK97 deleted the fix/ios-cut-formatting-corruption branch April 29, 2026 09:22
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.

Crashes due to deleting a mixed selection

1 participant