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

JustifiedText: Fix caret positioning when clicking on a trailing whitespace

When clicking in a TextEditor to position the caret, the caret would be
placed at the penultimate position when clicking at the end of a line
with trailing non-newline whitespaces.

Co-authored-by: Aga Janowicz <aga@roli.com>
This commit is contained in:
reuk 2025-10-15 14:04:05 +01:00
parent 3a0135ffb7
commit e525e12061
No known key found for this signature in database

View file

@ -499,23 +499,17 @@ int64 JustifiedText::getGlyphIndexToTheRightOf (Point<float> p) const
const auto glyphsInLine = shapedText.getGlyphs (lineIt->range); const auto glyphsInLine = shapedText.getGlyphs (lineIt->range);
auto glyphIndex = lineIt->range.getStart();
auto glyphX = lineIt->value.anchor.getX(); auto glyphX = lineIt->value.anchor.getX();
for (const auto& glyph : glyphsInLine) for (const auto [glyphIndex, glyph] : enumerate (glyphsInLine, lineIt->range.getStart()))
{ {
if ( p.getX() < glyphX + glyph.advance.getX() / 2.0f if (p.getX() < glyphX + glyph.advance.getX() / 2.0f || glyph.isNewline())
|| glyph.isNewline() return glyphIndex;
|| (glyphIndex - lineIt->range.getStart() == (int64) glyphsInLine.size() - 1 && glyph.isWhitespace()))
{
break;
}
++glyphIndex;
glyphX += glyph.advance.getX(); glyphX += glyph.advance.getX();
} }
return glyphIndex; return lineIt->range.getEnd();
} }
GlyphAnchorResult JustifiedText::getGlyphAnchor (int64 index) const GlyphAnchorResult JustifiedText::getGlyphAnchor (int64 index) const