wordpress-mobile / AztecEditor-Android

A reusable native Android rich text editor component.
Mozilla Public License 2.0
675 stars 112 forks source link

Cursor Jumps When Deleting Text Before Images on Devices with Nougat #213

Closed theck13 closed 7 years ago

theck13 commented 7 years ago

Expected

The cursor remains after text when using backspace to delete text surrounding images.

Observed

The cursor jumps before text when using backspace to delete text surrounding images. Note the behavior only occurs on devices with Nougat. Testing on emulators with Nougat and devices pre-Nougat do not show this behavior.

Reproduced

Before Image

  1. Move cursor immediately before image.
  2. Type "text" before image.
  3. Notice cursor is between "text" and image.
  4. Tap backspace kay.
  5. Notice cursor is between "te" and "t" letters.
  6. Tap backspace key.
  7. Notice cursor is before "et" letters.

After Image

  1. Move cursor immediately after image.
  2. Type "text" after image.
  3. Notice cursor is after "text" letters.
  4. Tap backspace kay.
  5. Notice cursor is between "te" and "t" letters.
  6. Tap backspace key.
  7. Notice cursor is before "et" letters.

Tested

Google Pixel on Android 7.1.1 with AztecDemo 1.0

hypest commented 7 years ago

It seems that the bug is caused by https://github.com/wordpress-mobile/WordPress-Aztec-Android/blob/5d1ca192ebdddbc9a12303fc6fbdee14fbbbb0ee/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt#L871-L873. Our code messes up the order of some of the events emitted by the EditText ending up in a selectionChanged event before the text-changed events. That causes the cursor to move and then the character be deleted which of course deletes the wrong character.

rachelmcr commented 7 years ago

I also noticed this happening when I try to delete text in the title field. The cursor moves back one space and then deletes a character, so I can't fully delete the title.

Tested on Nexus 9, Android 7.1.1, WPAndroid alpha-35.

rachelmcr commented 7 years ago

Actually, I am seeing this in both the title and content fields in the editor on my device. I can't delete text normally at all, even if the post content includes only text.

zandyring commented 7 years ago

I see what Rachel sees as well - If I've written abc in the content area and want to delete the b I place the cursor between the b and the c - and the a is deleted. It sometimes seems to "fix" by deleting the return before the word, if it's the first word on a line. But it's inconsistent. This is without images in the post. Android 6.0, alpha-35.

kraftbj commented 7 years ago

Also seen on Pixel XL, Android 7.1.1 (latest pure Android), alpha-35. I have a video if it occurring in the title field if it is helpful.

hypest commented 7 years ago

FYI, this is fixed with #278 but note that, as of writing, that PR is not merged yet.

0nko commented 7 years ago

Fixed by #278.