wordpress-mobile / AztecEditor-Android

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

Make sure to save remove action to history #1038

Closed planarvoid closed 1 year ago

planarvoid commented 1 year ago

Fix

Add undo action to removeItem operation in the placeholders.

Before you start make sure you setup the MainActivity like this:

Set the EXAMPLE to:

        private val EXAMPLE = """
            <p>Line</p>
            <placeholder type="image_with_caption" src="https://file-examples.com/storage/fed220eb286401af1a43037/2017/10/file_example_JPG_100kB.jpg" caption="Caption 1"
            <p>Line</p>
        """.trimIndent()

Create a placeholderManager field:

    protected lateinit var placeholderManager: PlaceholderManager

and initialize it in onCreate:

        placeholderManager = PlaceholderManager(visualEditor, findViewById(R.id.container_frame_layout))
        placeholderManager.registerAdapter(ImageWithCaptionAdapter())

and set it on aztec as media deleted listener and as a plugin:

 aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
                ...
                .addOnMediaDeletedListener(placeholderManager)
               ...
                .addPlugin(placeholderManager)

Test

  1. Launch the MainActivity
  2. Press backspace behind the placeholder
  3. Notice it disappears
  4. Click on "undo"
  5. Notice it jumps back

Review

@khaykov

Make sure strings will be translated: