wordpress-mobile / AztecEditor-Android

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

Issues with placeholders #997

Closed planarvoid closed 2 years ago

planarvoid commented 2 years ago

Fix

This PR fixes 2 issues. A crash that sometimes happens when you rotate your device while inserting. In that case the layout might not yet be there so I've added a delay to wait for the layout up to 500ms.

The second issue happens when deleting multiple media. The previous solution was using a list which was problematic when deleting multiple media fast. In that case There were concurrency issues and not all onMediaDeleted callbacks were called.

To test change the MainActivity so that the ImageWithCaption adapter is set up. This means add this:

private lateinit var placeholderManager: PlaceholderManager
override fun onCreate(savedInstanceState: Bundle?) {
        ...
        placeholderManager = PlaceholderManager(visualEditor, findViewById(R.id.container_frame_layout))
        placeholderManager.registerAdapter(ImageWithCaptionAdapter())
        ...
        Aztec.with(...)
                .addOnMediaDeletedListener(placeholderManager)
                .addPlugin(placeholderManager)
}
    override fun onDestroy() {
        super.onDestroy()
        placeholderManager.onDestroy()
        ...
        }

and change the EXAMPLE to something like this:

"""
<h1>Test</h1>
<placeholder type="image_with_caption" src="https://file-examples.com/storage/fe91f87fd962e70179469a5/2017/10/file_example_JPG_100kB.jpg" caption="image1" />
<placeholder type="image_with_caption" src="https://file-examples.com/storage/fe91f87fd962e70179469a5/2017/10/file_example_JPG_100kB.jpg" caption="image2" />
<placeholder type="image_with_caption" src="https://file-examples.com/storage/fe91f87fd962e70179469a5/2017/10/file_example_JPG_100kB.jpg" caption="image3" />
<placeholder type="image_with_caption" src="https://file-examples.com/storage/fe91f87fd962e70179469a5/2017/10/file_example_JPG_100kB.jpg" caption="image4" />
                        """.trimIndent()

Test

  1. Run the app with the changes described above
  2. Place the cursor after all the images
  3. Press "Backspace" multiple times fast
  4. Notice all the images are correctly deleted

Review

@khaykov

Make sure strings will be translated: