Skip to content

Conversation

@planarvoid
Copy link
Contributor

Fix

There is an issue that when there are no blocks in the selection and the user wants to add an image. In that case the selection is set to 0 and the image is added to the beginning of the editor.

I've added unit tests to cover this functionality as well

Test

  1. Turn on aztec.visualEditor.addMediaAfterBlocks() in the MainActivity
  2. Set EXAMPLE to something like <h1>Test 1</h1>\nBody
  3. Run the app
  4. Click at the end of Body
  5. Add an image
  6. Check it gets added after the Body and not at the beginning of the editor

Review

@AmandaRiu

Make sure strings will be translated:

  • 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 planarvoid added the bug label Apr 11, 2022
@planarvoid planarvoid requested a review from AmandaRiu April 11, 2022 09:22
@planarvoid planarvoid self-assigned this Apr 11, 2022
@planarvoid planarvoid requested a review from malinajirka April 12, 2022 08:07
@malinajirka malinajirka removed their request for review April 13, 2022 04:46
Copy link
Contributor

@AmandaRiu AmandaRiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@planarvoid One thing I did notice is that if nothing is selected then the image is added to the end of the last block span detected which seems fine until you have regular text following the block. For example, if I set the EXAMPLE text to "<h1>Test 1</h1>\nMy Test", then run the app and just tap to add a photo (without tapping inside the editor so selectionEnd is 0), then the image is added between the Heading and the body. This is an edge case I realize and I'm not sure what the fix would be in that case other than either defaulting the position to either 0 to add the image to the top of the document, or to editableText.length to return the position at the end of the document. I think the second option would keep everything in line with expected functionality for Aztec, but either way I'm not sure it's a big enough problem to address in this PR.

I also added a code comment for your review. Everything works great so approved, but will wait to merge in case you are still online to look at this real quick.

planarvoid and others added 2 commits April 13, 2022 16:19
…Formatter.kt

Co-authored-by: AmandaRiu <5810477+AmandaRiu@users.noreply.github.com>
…ust put the inserted item at the beginning of the text
@planarvoid
Copy link
Contributor Author

thanks for the review @AmandaRiu

One thing I did notice is that if nothing is selected then the image is added to the end of the last block span detected which seems fine until you have regular text following the block. For example, if I set the EXAMPLE text to "

Test 1

\nMy Test", then run the app and just tap to add a photo (without tapping inside the editor so selectionEnd is 0), then the image is added between the Heading and the body. This is an edge case I realize and I'm not sure what the fix would be in that case other than either defaulting the position to either 0 to add the image to the top of the document, or to editableText.length to return the position at the end of the document. I think the second option would keep everything in line with expected functionality for Aztec, but either way I'm not sure it's a big enough problem to address in this PR.

Good catch 👍 , I've added an edgecase solution just for this usecase (if selection start and end are 0, insert at the beginning of the entry).

@AmandaRiu
Copy link
Contributor

Changes look good! I'll merge as soon as CI has passed 👍🏻

@AmandaRiu AmandaRiu merged commit 39bf99b into release/1.5.6 Apr 13, 2022
@AmandaRiu AmandaRiu deleted the fix/add-block-when-no-blocks-present branch April 13, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants