Right in the beginning, when the Document is empty, this returns 1.
The length of the document is of course 0.
By the way, your non-labs External Tool node has the same problem, I just double-checked.
In most of the code snippets around the web, people use
doc.getEndPosition().getOffset() - 1.
Not sure if the JDK “fixed” something here from 8 to 11.
P.S.: In case you guys make some changes there, it would be cool if the API for adding single lines (kind of used in the View itself) would be exposed publicly in the model somehow It would be a bit more efficient than setting the whole text everytime. As long as it does not invalidate any internal state or preconditions of course.