Skip to content

Commit 4344e7f

Browse files
committed
Update all the placeholders on content change
1 parent aa17b7c commit 4344e7f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,22 @@ class PlaceholderManager(
114114
return drawable
115115
}
116116

117-
private suspend fun updateAllBelowSelection(selectionStart: Int) {
118-
positionToId.filter {
119-
it.elementPosition >= selectionStart - 1
120-
}.forEach {
117+
/**
118+
* Call this method to reload all the placeholders
119+
*/
120+
suspend fun refresh() {
121+
positionToId.forEach {
121122
insertContentOverSpanWithId(it.uuid)
122123
}
123124
}
124125

126+
/**
127+
* Call this method to relaod a placeholder with UUID
128+
*/
129+
suspend fun refreshWithUuid(uuid: String) {
130+
insertContentOverSpanWithId(uuid)
131+
}
132+
125133
private suspend fun insertContentOverSpanWithId(uuid: String) {
126134
var aztecAttributes: AztecAttributes? = null
127135
val predicate = object : AztecText.AttributePredicate {
@@ -218,7 +226,7 @@ class PlaceholderManager(
218226
*/
219227
override fun onContentChanged() {
220228
launch {
221-
updateAllBelowSelection(aztecText.selectionStart)
229+
refresh()
222230
}
223231
}
224232

0 commit comments

Comments
 (0)