It looks like a code defect, but you are the judge.
See replaceText () in BaseInputConnection . I believe this is the code that places the cursor after insertion. ( replaceText() is called from commitText()) .
In the reference code a is the beginning of the selection. b is the end of the choice. Since there is no choice in the example, and the cursor is at index 1, a == b == 1 . In addition, new text (aaa) is not inserted (replacing the selection [a, b]) until the cursor is moved to the new one.
Selection.setSelection(content, newCursorPosition) sets the cursor position, so for 0 and 1 to create identical positioning in your example, I expect the derived value of newCursorPosition be the same for both inputs.
Using the cursor located between two 8 at position 1, consider the following code:
if (newCursorPosition > 0) { newCursorPosition += b - 1; } else { newCursorPosition += a; }
For input 1, newCursorPosition > 0, so newCursorPosition = newCursorPosition + 1 - 1 or 1.
For your input 0, newCursorPosition not 0, so newCursorPosition = newCursorPosition + a (0 + 1) or 1.
Since both inputs give the same value, I would expect Selection.setSelection(content, newCursorPosition) to get the results you see.
I did not execute the code in this place, but I believe that this is a problem. I followed the execution paths in BaseInputConnection for newCursorPosition = 0 and newCursorPosition = 1 on the Pixel Emulator with API 21 and what is described above fails.