@@ -51,7 +51,10 @@ class EnrichedTextInputView : AppCompatEditText {
5151 val paragraphStyles: ParagraphStyles ? = ParagraphStyles (this )
5252 val listStyles: ListStyles ? = ListStyles (this )
5353 val parametrizedStyles: ParametrizedStyles ? = ParametrizedStyles (this )
54- var isSettingValue: Boolean = false
54+ // Sometimes setting up style triggers many changes in sequence
55+ // Eg. removing conflicting styles -> changing text -> applying spans
56+ // In such scenario we want to prevent from handling side effects (eg. onTextChanged)
57+ var isDuringTransaction: Boolean = false
5558 var isRemovingMany: Boolean = false
5659
5760 val mentionHandler: MentionHandler ? = MentionHandler (this )
@@ -233,7 +236,7 @@ class EnrichedTextInputView : AppCompatEditText {
233236
234237 fun setValue (value : CharSequence? ) {
235238 if (value == null ) return
236- isSettingValue = true
239+ isDuringTransaction = true
237240
238241 val newText = parseText(value)
239242 setText(newText)
@@ -244,7 +247,7 @@ class EnrichedTextInputView : AppCompatEditText {
244247 // Scroll to the last line of text
245248 setSelection(text?.length ? : 0 )
246249
247- isSettingValue = false
250+ isDuringTransaction = false
248251 }
249252
250253 fun setAutoFocus (autoFocus : Boolean ) {
@@ -452,13 +455,13 @@ class EnrichedTextInputView : AppCompatEditText {
452455 val end = selection?.end ? : 0
453456 val lengthBefore = text?.length ? : 0
454457
455- isSettingValue = true
458+ isDuringTransaction = true
456459 val targetRange = getTargetRange(name)
457460 val removed = removeStyle(style, targetRange.first, targetRange.second)
458461 if (removed) {
459462 spanState?.setStart(style, null )
460463 }
461- isSettingValue = false
464+ isDuringTransaction = false
462465
463466 val lengthAfter = text?.length ? : 0
464467 val charactersRemoved = lengthBefore - lengthAfter
0 commit comments