@@ -77,6 +77,26 @@ class PlaceholderManager(
7777 insertContentOverSpanWithId(attrs.getValue(UUID_ATTRIBUTE ), null )
7878 }
7979
80+ /* *
81+ * Call this method to remove a placeholder from both the AztecText and the overlaying layer programatically.
82+ * @param predicate determines whether a span should be removed
83+ */
84+ fun removeItem (predicate : (AztecAttributes ) -> Boolean ) {
85+ aztecText.editableText.getSpans(0 , aztecText.length(), AztecPlaceholderSpan ::class .java).filter {
86+ predicate(it.attributes)
87+ }.forEach { placeholderSpan ->
88+ val startIndex = aztecText.editableText.getSpanStart(placeholderSpan)
89+ val endIndex = aztecText.editableText.getSpanEnd(placeholderSpan)
90+ aztecText.editableText.getSpans(startIndex, endIndex, AztecMediaClickableSpan ::class .java).forEach {
91+ aztecText.editableText.removeSpan(it)
92+ }
93+ aztecText.editableText.removeSpan(placeholderSpan)
94+ aztecText.editableText.delete(startIndex, endIndex)
95+ onMediaDeleted(placeholderSpan.attributes)
96+ }
97+ aztecText.refreshText(false )
98+ }
99+
80100 private fun buildPlaceholderDrawable (adapter : PlaceholderAdapter , attrs : AztecAttributes ): Drawable {
81101 val drawable = ContextCompat .getDrawable(aztecText.context, android.R .color.transparent)!!
82102 updateDrawableBounds(adapter, attrs, drawable)
0 commit comments