The source code for setCaretOffset()
shows that if you use an offset greater than the length of the text, then instead the length of the text is used, almost putting the caret at the end of the text. Therefore, setting Integer.MAX_VALUE
as an offset is a viable option, without requiring any text length checks.
If you canβt get a notification when the flushing has really ended, I suggest that you postpone the carriage placement for a few hundred milliseconds. It will not be distracting for the user and provides a reliable solution for you.
For reference, here is the source code for setCaretOffset()
:
public void setCaretOffset(int offset) { checkWidget(); int length = getCharCount(); if (length > 0 && offset != caretOffset) { if (offset < 0) { offset = 0; } else if (offset > length) { offset = length;
source share