TextEditor::getCaretRectangle() returns wrong position

I found that it almost always returns y <= 0.
In file juce_TextEditor.cpp at line 1461:

Point<int> TextEditor::getTextOffset() const noexcept
{
    Iterator i (*this);
    auto yOffset = i.getYOffset();

    return { getLeftIndent() + borderSize.getLeft() - viewport->getViewPositionX(),
             roundToInt ((float) getTopIndent() + (float) borderSize.getTop() + yOffset) - viewport->getViewPositionY() };
}

If I comment out the last - viewport->getViewPositionY() I get the correct coordinate. Haven’t checked if this also affect the x coordinate.

I don’t know if this is a bug in the library or if I have to change something in my code. Fact is that a program that worked well with Juce 6.1.6 is now broken with Juce 7.0.5.

The code is here:

It’s a simple HTML 4 parser that I wrote for embedding user manuals with images in my products. The issue is with images that are not where they’re supposed to be (under the last caret position) but all moved to the top of the document.

As a workaround in my program, instead of using textEditor->getCaretRectangle().getY() to get the last y coordinate of the text, I’ll use textEditor->getTextHeight(), yet this doesn’t solve the problem with getCaretRectangle() which returns wrong x/y coords.