Well, I try to build a rich text editor.
I have some buttons to format my editable text (bold, italic, URL, etc.).
I use Google keyboard with all text correction options enabled (Settings > Language & input > Google keyboard > Text correction).
I do the following:
In my EditText
, I write some text.
I select it and apply a bold span with SPAN_EXCLUSIVE_EXCLUSIVE
(33) as flags.
Then, I move my cursor to the end.
Finally, I add text to the end of the text. Added text should be without bold.
Okay, here is the problem. My bold span flags has changed... Why!?
Here is some logs:
D/ContentUtils: beforeTextChanged: start end span flags
D/ContentUtils: beforeTextChanged: 0 7 ChangeWatcher 8388626
D/ContentUtils: beforeTextChanged: 0 7 ChangeWatcher 6553618
D/ContentUtils: beforeTextChanged: 0 7 TextKeyListener 18
D/ContentUtils: beforeTextChanged: 0 7 SpanController 18
D/ContentUtils: beforeTextChanged: 7 7 START 546
D/ContentUtils: beforeTextChanged: 7 7 END 34
D/ContentUtils: beforeTextChanged: 0 7 SpellCheckSpan 33
D/ContentUtils: beforeTextChanged: 0 7 CustomBoldSpan 33
D/ContentUtils: onTextChaghed
D/ContentUtils: onTextChaghed: 0 8 ChangeWatcher 8392722
D/ContentUtils: onTextChaghed: 0 8 ChangeWatcher 6557714
D/ContentUtils: onTextChaghed: 0 8 TextKeyListener 4114
D/ContentUtils: onTextChaghed: 0 8 SpanController 4114
D/ContentUtils: onTextChaghed: 8 8 START 546
D/ContentUtils: onTextChaghed: 8 8 END 34
D/ContentUtils: onTextChaghed: 0 8 CustomBoldSpan 4129
D/ContentUtils: onTextChaghed: 0 8 UnderlineSpan 289
D/ContentUtils: onTextChaghed: 0 8 ComposingText 289
D/ContentUtils: afterTextChanged
D/ContentUtils: afterTextChanged: 0 8 ChangeWatcher 8392722
D/ContentUtils: afterTextChanged: 0 8 ChangeWatcher 6557714
D/ContentUtils: afterTextChanged: 0 8 TextKeyListener 4114
D/ContentUtils: afterTextChanged: 0 8 SpanController 4114
D/ContentUtils: afterTextChanged: 8 8 START 546
D/ContentUtils: afterTextChanged: 8 8 END 34
D/ContentUtils: afterTextChanged: 0 8 CustomBoldSpan 4129
D/ContentUtils: afterTextChanged: 0 8 UnderlineSpan 289
D/ContentUtils: afterTextChanged: 0 8 ComposingText 289
D/ContentUtils: afterTextChanged: 0 8 SpellCheckSpan 33
When I use another keyboard, all went fine.
When I disabled Text correction settings, all went fine.
All of my span are custom span and subclass an existing Android span.
It seems Google Keyboard modify my spans by its own (probably because of Show suggestions
settings).
How can I avoid this?
Maybe I am missing something about span flags?