LibWeb/Painting: Place text cursor using GlyphRun font

This makes the cursor appear in the correct place when the text makes
use of multiple different fonts.
This commit is contained in:
Sam Atkins 2024-12-05 19:38:24 +00:00 committed by Alexander Kalenik
commit 00302b5b1e
Notes: github-actions[bot] 2024-12-06 01:58:28 +00:00

View file

@ -570,8 +570,9 @@ void paint_cursor_if_needed(PaintContext& context, TextPaintable const& paintabl
auto fragment_rect = fragment.absolute_rect();
auto text = fragment.string_view();
auto const& font = fragment.glyph_run() ? fragment.glyph_run()->font() : fragment.layout_node().first_available_font();
CSSPixelRect cursor_rect {
fragment_rect.x() + CSSPixels::nearest_value_for(paintable.layout_node().first_available_font().width(text.substring_view(0, document.cursor_position()->offset() - fragment.start()))),
fragment_rect.x() + CSSPixels::nearest_value_for(font.width(text.substring_view(0, document.cursor_position()->offset() - fragment.start()))),
fragment_rect.top(),
1,
fragment_rect.height()