[Bug]: TextEditor::getTotalTextHeight() adds height for a newline twice

(I’ve created an issue and PR over on GitHub, but I’m posting this here because — let’s be honest — it looks like the GitHub issue/PR lists aren’t checked that often.)


  1. Create a juce::TextEditor, enable multi-line support and set the text to "a".
  2. Set a breakpoint in juce::TextEditor::getTotalTextHeight()
  3. Type in a newline after the "a"

The juce::TextEditor::getTotalTextHeight() function loops over all sections and atoms using while (next()) {}.

int getTotalTextHeight()
{
    while (next()) {}

    auto height = lineY + lineHeight + getYOffset();

    if (atom != nullptr && atom->isNewLine())
        height += lineHeight;

    return roundToInt (height);
}

The last of the next() calls ends up in moveToEndOfLastAtom():

void moveToEndOfLastAtom()
    {
        if (atom != nullptr)
        {
            atomX = atomRight;

            if (atom->isNewLine())
            {
                atomX = getJustificationOffsetX (0);
                lineY += lineHeight * lineSpacing;
            }
        }
    }

As you can ssee, movetoEndOfLastAtom() already adds a lineHeight if the last atom is a new line. But then when we step out back into getTotalTextHeight(), this function also adds extra height when the last character is a new line!

The total height ends up with an extra line, as can be verified in the debugger. If you look at the UI and the text height is bigger than the component height, you’ll see that the scroll bar has some “extra” space at the bottom for the double newline.

Bump. Any progress on this at all?

I don’t mean to sound sour, but this isn’t the first time I’ve reported a bug including a fix and opened an issue over on GitHub and all I get is tumbleweed and crickets.

I’m not freebeeing JUCE either, been working and paying for it (either directly or through an employer) for it for years now. I realize that doesn’t entitle people to fixes and some issues are hard to tackle, but I’ve even included a fix here.

2 Likes

Welcome to the juce sound of silence pal. Get used to it. All the best with your pull requests !

1 Like