@@ -100,22 +100,23 @@ class PlaceholderManager(
100100 * Call this method to insert an item with an option to merge it with the previous item. This could be used to
101101 * build a gallery of images on adding a new image.
102102 * @param type placeholder type
103+ * @param shouldMergeItem this method should return true when the previous type is compatible and should be updated
103104 * @param updateItem function to update current parameters with new params
104105 */
105- suspend fun insertOrUpdateItem (type : String , updateItem : (currentAttributes: Map <String , String >? , currentType: String? ) -> Map <String , String >) {
106+ suspend fun insertOrUpdateItem (type : String , shouldMergeItem : (currentItemType: String ) -> Boolean = { true }, updateItem : (currentAttributes: Map <String , String >? , currentType: String? ) -> Map <String , String >) {
106107 val from = (aztecText.selectionStart - 1 ).coerceAtLeast(0 )
107108 val editableText = aztecText.editableText
108109 val currentItem = editableText.getSpans(
109110 from,
110111 aztecText.selectionStart,
111112 AztecPlaceholderSpan ::class .java
112113 ).lastOrNull()
113- if (currentItem != null ) {
114+ val currentType = currentItem?.attributes?.getValue(TYPE_ATTRIBUTE )
115+ if (currentType != null && shouldMergeItem(currentType)) {
114116 val adapter = adapters[type]
115117 ? : throw IllegalArgumentException (" Adapter for inserted type not found. Register it with `registerAdapter` method" )
116118 val currentAttributes = mutableMapOf<String , String >()
117119 val uuid = currentItem.attributes.getValue(UUID_ATTRIBUTE )
118- val currentType = currentItem.attributes.getValue(TYPE_ATTRIBUTE )
119120 for (i in 0 until currentItem.attributes.length) {
120121 val name = currentItem.attributes.getQName(i)
121122 val value = currentItem.attributes.getValue(name)
0 commit comments