The documentation for InputConnection.commitText(CharSequence text, int newCursorPosition)
says that newCursorPosition
means:
int: The new cursor position around the text, in Java characters. If > 0, this is relative to the end of the text - 1; if <= 0, this is relative to the start of the text. So a value of 1 will always advance the cursor to the position after the full text being inserted. Note that this means you can't position the cursor within the text, because the editor can make modifications to the text you are providing so it is not possible to correctly specify locations there.
In this example, if I enter two characters, then position the cursor between them like this
and then enter another character, it doesn't matter if I set newCursorPosition
to 0
or 1
. The cursor is always at the end of the insertion. For example calling
inputConnection.commitText("aaa", 0);
or
inputConnection.commitText("aaa", 1);
Both show the cursor like this:
If I do -1
with
inputConnection.commitText("aaa", -1);
I get this
The 1
and -1
results are expected as per the documentation. Why doesn't 0
put the cursor at the beginning of the insertion? I would expect 0
should be like this
inputConnection.commitText("aaa", 0);
but it isn't. Why not?