mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +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:
parent
3a0135ffb7
commit
e525e12061
1 changed files with 4 additions and 10 deletions
|
|
@ -499,23 +499,17 @@ int64 JustifiedText::getGlyphIndexToTheRightOf (Point<float> p) const
|
|||
|
||||
const auto glyphsInLine = shapedText.getGlyphs (lineIt->range);
|
||||
|
||||
auto glyphIndex = lineIt->range.getStart();
|
||||
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
|
||||
|| glyph.isNewline()
|
||||
|| (glyphIndex - lineIt->range.getStart() == (int64) glyphsInLine.size() - 1 && glyph.isWhitespace()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (p.getX() < glyphX + glyph.advance.getX() / 2.0f || glyph.isNewline())
|
||||
return glyphIndex;
|
||||
|
||||
++glyphIndex;
|
||||
glyphX += glyph.advance.getX();
|
||||
}
|
||||
|
||||
return glyphIndex;
|
||||
return lineIt->range.getEnd();
|
||||
}
|
||||
|
||||
GlyphAnchorResult JustifiedText::getGlyphAnchor (int64 index) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue