Skip to content

fix: preserve selection history between text changes - #15

Draft
fkreinh wants to merge 1 commit into
appandflow:mainfrom
fkreinh:fix/preserve-selection-history
Draft

fix: preserve selection history between text changes#15
fkreinh wants to merge 1 commit into
appandflow:mainfrom
fkreinh:fix/preserve-selection-history

Conversation

@fkreinh

@fkreinh fkreinh commented Aug 31, 2026

Copy link
Copy Markdown

Summary

  • keep previousSelection synchronized when the user moves the cursor without changing text on iOS, Android, and web
  • seed native transformer history and the imperative ref from the transformed default value
  • add regression coverage for history seeding, initial ref values, and web cursor-only movements

Problem

The transformer history only advanced after text changes. If a user tapped into the middle of a formatted value and typed, the next transform still received the selection from the preceding edit. Formatters that use previousSelection could therefore interpret the edit at the wrong position and move the caret or modify the wrong digits.

For example, with 12.34 displayed, tapping between 2 and . and typing 5 should use that tapped position as previousSelection. Before this change, the transformer could still receive the selection at the end of 12.34.

Implementation

  • iOS synchronizes history from selection callbacks while guarding selection callbacks that belong to an in-progress text edit.
  • Android observes the EditText selection marker spans and synchronizes history after selection-only changes.
  • Web updates its stored previous state from onSelectionChange when the DOM value has not changed.
  • Initial values seed both the native transformer history and getValue.

There is no public API change.

The contribution guide asks contributors to discuss implementation changes in an issue first, but issue creation is currently restricted for this repository. I opened this as a draft so the implementation can be discussed here before it is marked ready.

Testing

  • yarn test: 8 suites, 126 tests passed
  • yarn lint: passed with 0 errors; 246 existing warnings from generated phone data and one existing unused directive
  • yarn format:check: passed
  • validated in a consuming React Native app on iOS and Android

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.

1 participant