mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibGUI: Make Gfx- to text-positioning handle multi-code point glyphs
This commit is contained in:
parent
36a495e87e
commit
16ec116133
1 changed files with 13 additions and 10 deletions
|
@ -169,20 +169,23 @@ TextPosition TextEditor::text_position_at_content_position(Gfx::IntPoint content
|
||||||
for_each_visual_line(line_index, [&](Gfx::IntRect const& rect, auto& view, size_t start_of_line, [[maybe_unused]] bool is_last_visual_line) {
|
for_each_visual_line(line_index, [&](Gfx::IntRect const& rect, auto& view, size_t start_of_line, [[maybe_unused]] bool is_last_visual_line) {
|
||||||
if (is_multi_line() && !rect.contains_vertically(position.y()) && !is_last_visual_line)
|
if (is_multi_line() && !rect.contains_vertically(position.y()) && !is_last_visual_line)
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
||||||
column_index = start_of_line;
|
column_index = start_of_line;
|
||||||
|
int glyph_x = 0;
|
||||||
|
|
||||||
if (position.x() <= 0) {
|
if (position.x() <= 0) {
|
||||||
// We're outside the text on the left side, put cursor at column 0 on this visual line.
|
// We're outside the text on the left side, put cursor at column 0 on this visual line.
|
||||||
} else {
|
return IterationDecision::Break;
|
||||||
int glyph_x = 0;
|
|
||||||
size_t i = 0;
|
|
||||||
for (; i < view.length(); ++i) {
|
|
||||||
int advance = font().glyph_or_emoji_width(view.code_points()[i]) + font().glyph_spacing();
|
|
||||||
if ((glyph_x + (advance / 2)) >= position.x())
|
|
||||||
break;
|
|
||||||
glyph_x += advance;
|
|
||||||
}
|
|
||||||
column_index += i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto it = view.begin(); it != view.end(); ++it, ++column_index) {
|
||||||
|
int advance = font().glyph_or_emoji_width(it) + font().glyph_spacing();
|
||||||
|
if ((glyph_x + (advance / 2)) >= position.x())
|
||||||
|
break;
|
||||||
|
|
||||||
|
glyph_x += advance;
|
||||||
|
}
|
||||||
|
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue