summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-02-22 12:41:58 -0500
committerLinus Groh <mail@linusgroh.de>2023-02-24 20:28:23 +0100
commit16ec116133f5e7c2d1a2c1a5d3c2140b97d143a4 (patch)
tree07c0b1a4688b0b278bf0ae308f2da4906416fa5d
parent36a495e87ef4b16236678df0e090082474f9972c (diff)
downloadserenity-16ec116133f5e7c2d1a2c1a5d3c2140b97d143a4.zip
LibGUI: Make Gfx- to text-positioning handle multi-code point glyphs
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 4881247094..9428a62191 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -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) {
if (is_multi_line() && !rect.contains_vertically(position.y()) && !is_last_visual_line)
return IterationDecision::Continue;
+
column_index = start_of_line;
+ int glyph_x = 0;
+
if (position.x() <= 0) {
// We're outside the text on the left side, put cursor at column 0 on this visual line.
- } else {
- 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;
+ return IterationDecision::Break;
}
+
+ 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;
});
break;