1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

TextLayout: Preserve leading whitespaces

This fixes the CodeEditorComponent regression present since
03e79f8f12.
This commit is contained in:
attila 2024-06-19 18:24:38 +02:00 committed by Attila Szarvas
parent ef8417023e
commit 3c4aa8d0ce

View file

@ -456,13 +456,23 @@ void TextLayout::createStandardLayout (const AttributedString& text)
run->font = font;
run->colour = colour;
for (decltype (glyphs.size()) i = 0, iMax = glyphs.size(); i < iMax; ++i)
const auto beyondLastNonWhitespace = [&]
{
if (glyphs[i].whitespace)
continue;
auto i = glyphs.size();
for (auto it = std::reverse_iterator { glyphs.end() },
end = std::reverse_iterator { glyphs.begin() };
it != end && it->whitespace;
++it)
{
--i;
}
return i;
}();
for (size_t i = 0; i < beyondLastNonWhitespace; ++i)
run->glyphs.add ({ (int) glyphs[i].glyphId, positions[i] - line->lineOrigin, glyphs[i].advance.x });
}
line->runs.add (std::move (run));
},