AztecEditor-Android icon indicating copy to clipboard operation
AztecEditor-Android copied to clipboard

Make setSelection safe

Open planarvoid opened this issue 2 years ago • 2 comments

Fix

We're having occasional issues when the setSelection is called out of bounds of the text. While it would be better to fix the underlying issues, I think this is a safe approach to handling this. What usually crashes the app is something like this:

  • Preserve cursor position N at the end of text
  • Set the cursor position to 0
  • Do some modification to the text that shorten the text to N - 1
  • Try to set the cursor position to N
  • Crash because text length is N-1 < N

This solution handles that case and if this happens, sets the selection to N-1 instead. I can't think of a case where this might be an issue but let me know if you think it's unsafe.

Review

@danilo04

Make sure strings will be translated:

  • [x] If there are new strings that have to be translated, I have added them to the client's strings.xml as a part of the integration PR.

planarvoid avatar Oct 10 '23 09:10 planarvoid

possible related to https://github.com/wordpress-mobile/AztecEditor-Android/issues/848

Bibazavr avatar Nov 19 '24 12:11 Bibazavr

I've checked this solution and this fixes crash from https://github.com/wordpress-mobile/AztecEditor-Android/issues/848

Bibazavr avatar Nov 19 '24 12:11 Bibazavr