wordpress-mobile / AztecEditor-Android

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

Make sure media and horizontal rule are only added after the currently selected block #974

Closed planarvoid closed 2 years ago

planarvoid commented 2 years ago

Fix

The media and the horizontal rule are currently added inline. For example you can add an image as a list item. In this PR I'm adding a setting where you can disable this behaviour. The new functionality adds a media item or a HR after the currently selected block. In addition to this when deleting text before an image (with backspace), the selection is moved so that you don't end up moving the image to become a part of the previous block.

Test 1

  1. Make sure the functionality is enabled - call aztec.visualEditor.addMediaAfterBlocks() in the MainActivity
  2. Click in a block (list, quote, code, heading)
  3. Insert an image/video/horizontal rule
  4. Notice it gets added after the currently selected block

Test 2

  1. Make sure the functionality is disabled
  2. Click in a block (list, quote, code, heading)
  3. Insert an image/video/horizontal rule
  4. Notice it gets in the block as before

Test 3

  1. Enable the functionality and add a block in Test 1
  2. Move cursor right before the item you added (with arrows)
  3. Click on "backspace"
  4. Notice the cursor is moved at the end of previous block and you can delete the previous block now

Test 4

  1. Enable the functionality and add a block in Test 1
  2. Move cursor right after the item you added (with arrows)
  3. Click on "backspace"
  4. Notice the item is deleted correctly

Review

@AmandaRiu

Make sure strings will be translated:

planarvoid commented 2 years ago

thanks for the review @AmandaRiu ! the issue was caused by not adding \n before the <hr> when it was added as a block. This is necessary because otherwise the hr is part either of the previous or the following block item. I'm still not 100% sure why the new h2 was created but adding the \n fixes the issue (I've done that with the images before).

planarvoid commented 2 years ago

I forgot to push it @AmandaRiu 🤦