(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.)
- Create a
juce::TextEditor
, enable multi-line support and set the text to"a"
. - Set a breakpoint in
juce::TextEditor::getTotalTextHeight()
- 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.