wordpress-mobile / AztecEditor-Android

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

Updated span removal logic when using exclusiveBlocks #1002

Closed khaykov closed 1 year ago

khaykov commented 1 year ago

This PR fixes issue with adding new block spans right next to the existing ones, when exclusiveBlocks is set to true.

To test this PR and the original issue you need to add aztec:exclusiveBlocks="true" to AztecText layout.

When exclusiveBlocks is set to true the block are replaced when other block style is applied to them (normal behavior is to allow multiple block style to be applied).

Issue was caused because the range we used to detect spans we should remove included the span on the line before the cursor. I used the range logic from the toolbar highlight code, which I believe is more accurate.

Steps to reproduce original issue:

  1. Create a list with one element in it.
  2. Press enter to add a second element element, and press enter again to remove it a start a new line.
  3. Add a quote.
  4. Notice that the list styling has disappeared.

Image from Gyazo

Test

  1. Create a list with one element in it.
  2. Press enter to add a second element element, and press enter again to remove it a start a new line.
  3. Add a quote.
  4. Notice that the quote is added correctly and list style remains.

This behavior affects block styles, like Lists, Quotes and Headings. Try testing it in various ways - applying block styles in the middle of multiline block element, at the beginning and at the end.