@@ -18,8 +18,7 @@ class EndOfBufferMarkerAdder(text: Editable) : TextWatcher {
18
18
override fun beforeTextChanged (s : CharSequence , start : Int , count : Int , after : Int ) {}
19
19
20
20
override fun onTextChanged (s : CharSequence , start : Int , before : Int , count : Int ) {
21
- // count < before to take into account auto-corrected words
22
- deletedText = before > 0 && count < before
21
+ deletedText = before > 0
23
22
}
24
23
25
24
override fun afterTextChanged (text : Editable ) {
@@ -32,9 +31,26 @@ class EndOfBufferMarkerAdder(text: Editable) : TextWatcher {
32
31
// by the way, the cursor will be adjusted "automatically" by RichTextEditText's onSelectionChanged to before the marker
33
32
}
34
33
34
+ fun uninstallEndOfBuffer (aztecText : AztecText ) {
35
+ uninstall(aztecText)
36
+ }
37
+
35
38
companion object {
36
- fun install (editText : AztecText ) {
37
- editText.addTextChangedListener(EndOfBufferMarkerAdder (editText.text))
39
+ private val watchers = mutableMapOf<AztecText , EndOfBufferMarkerAdder >()
40
+
41
+ fun install (editText : AztecText ): EndOfBufferMarkerAdder {
42
+ var watcher = EndOfBufferMarkerAdder (editText.text)
43
+ editText.addTextChangedListener(watcher)
44
+ watchers[editText] = watcher
45
+ return watcher
46
+ }
47
+
48
+ fun uninstall (editText : AztecText ) {
49
+ val watcher = watchers[editText]
50
+ if (watcher != null ) {
51
+ editText.removeTextChangedListener(watcher)
52
+ watchers.remove(editText)
53
+ }
38
54
}
39
55
40
56
fun ensureEndOfTextMarker (text : Editable , deletedText : Boolean = false): Editable {
@@ -45,9 +61,7 @@ class EndOfBufferMarkerAdder(text: Editable) : TextWatcher {
45
61
if (text.isEmpty()) {
46
62
if (text.getSpans(0 , 0 , IAztecBlockSpan ::class .java).isNotEmpty()) {
47
63
// need to add a end-of-text marker so a block element can render in the empty text.
48
- if (! deletedText) {
49
- text.append(Constants .END_OF_BUFFER_MARKER )
50
- }
64
+ text.append(Constants .END_OF_BUFFER_MARKER )
51
65
}
52
66
return text
53
67
} else if (text.length == 1 && text[0 ] == Constants .END_OF_BUFFER_MARKER && deletedText) {
0 commit comments