Google keyboard messed up my user range

Well, I'm trying to create a rich text editor. I have several buttons for formatting editable text (bold, italics, URL, etc.).
I use a Google keyboard with all text correction options turned on ( Settings > Language & Input > Google Keyboard > Text Correction ).

I do the following:

In my EditText I am writing text.
text

I select it and apply bold interval with SPAN_EXCLUSIVE_EXCLUSIVE (33) as flags.
the selected text
enter image description here

Then I move the cursor to the end.
cursor at the end

Finally, I add text to the end of the text. Added text should not be highlighted. text in bold

Ok, here's the problem. My bold range flags have changed ... Why ??

Here are some magazines:

 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 a different keyboard, everything is going well.
When I turned off the text correction settings, everything went fine. My whole range is a custom range and a subclass of the existing Android range.

It seems that the Google Keyboard is changing my intervals to its own (possibly due to the Show suggestions settings).
How can i avoid this?
Maybe I'm missing something about span flags?

+7
android
source share
1 answer

Well, after some research, the keyboard seems to apply some spaces around the word when typing to manage sentences.

A problem for each letter printed, the word is deleted and added with the letter added. At this point, I am losing some user intervals, such as those in the middle of the word.

If you add a TextWatcher to an EditText , it will be called 2 times: first with the letter added, the second after deleting and adding the whole word. Not very convenient.

So the ugly solution is to copy all the gaps during beforeTextChanged() and apply back during the second afterTextChanged() . But it is difficult to implement.

In any case, other applications do not work better: GMail and Evernote have the same problems. I decided not to worry and not to use an ugly solution. My rich text editor can be used this way ...

+2
source share

All Articles