@@ -74,6 +74,7 @@ import org.wordpress.aztec.handlers.ListItemHandler
7474import org.wordpress.aztec.handlers.PreformatHandler
7575import org.wordpress.aztec.handlers.QuoteHandler
7676import org.wordpress.aztec.plugins.IAztecPlugin
77+ import org.wordpress.aztec.plugins.ITextPastePlugin
7778import org.wordpress.aztec.plugins.IToolbarButton
7879import org.wordpress.aztec.source.Format
7980import org.wordpress.aztec.source.SourceViewEditText
@@ -1845,11 +1846,13 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
18451846 disableTextChangedListener()
18461847
18471848 val length = text.length
1849+ var selectedText: String? = null
18481850 if (min == 0 && max == 0 && length == 1 && text.toString() == Constants .END_OF_BUFFER_MARKER_STRING ) {
18491851 editable.insert(min, Constants .REPLACEMENT_MARKER_STRING )
18501852 } else if (min == 0 && max == length) {
18511853 setText(Constants .REPLACEMENT_MARKER_STRING )
18521854 } else {
1855+ selectedText = editable.substring(min, max)
18531856 // prevent changes here from triggering the crash preventer
18541857 disableCrashPreventerInputFilter()
18551858 editable.delete(min, max)
@@ -1875,7 +1878,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
18751878 else clip.getItemAt(0 ).coerceToHtmlText(AztecParser (alignmentRendering, plugins))
18761879
18771880 val oldHtml = toPlainHtml().replace(" <aztec_cursor>" , " " )
1878- val newHtml = oldHtml.replace(Constants .REPLACEMENT_MARKER_STRING , textToPaste + " <" + AztecCursorSpan .AZTEC_CURSOR_TAG + " >" )
1881+ val pastedHtmlText = plugins.filterIsInstance<ITextPastePlugin >().fold(textToPaste) { acc, plugin ->
1882+ if (selectedText.isNullOrEmpty()) {
1883+ plugin.toHtml(acc)
1884+ } else {
1885+ plugin.toHtml(selectedText, acc)
1886+ }
1887+ }
1888+ val newHtml = oldHtml.replace(Constants .REPLACEMENT_MARKER_STRING , pastedHtmlText + " <" + AztecCursorSpan .AZTEC_CURSOR_TAG + " >" )
18791889
18801890 fromHtml(newHtml, false )
18811891 inlineFormatter.joinStyleSpans(0 , length())
0 commit comments