diff --git a/third_party/txt/src/txt/paragraph_txt.cc b/third_party/txt/src/txt/paragraph_txt.cc index 3dbb38dedac2b..6ae4b75653626 100644 --- a/third_party/txt/src/txt/paragraph_txt.cc +++ b/third_party/txt/src/txt/paragraph_txt.cc @@ -1927,8 +1927,7 @@ Paragraph::PositionWithAffinity ParagraphTxt::GetGlyphPositionAtCoordinate( } if (gp == nullptr) { - const GlyphPosition& last_glyph = line_glyph_position.back(); - return PositionWithAffinity(last_glyph.code_units.end, UPSTREAM); + gp = &line_glyph_position.back(); } // Find the direction of the run that contains this glyph. diff --git a/third_party/txt/tests/paragraph_unittests.cc b/third_party/txt/tests/paragraph_unittests.cc index 81e2f64113345..5f0af37adac81 100644 --- a/third_party/txt/tests/paragraph_unittests.cc +++ b/third_party/txt/tests/paragraph_unittests.cc @@ -2465,6 +2465,50 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignParagraph)) { ASSERT_TRUE(Snapshot()); } +TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignRTLParagraphHitTest)) { + // Regression test for https://github.com/flutter/flutter/issues/54969. + const char* text = "بمباركة التقليدية قام عن. تصفح"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 1; + paragraph_style.text_align = TextAlign::left; + paragraph_style.text_direction = TextDirection::rtl; + txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection()); + + txt::TextStyle text_style; + text_style.font_families = std::vector(1, "Roboto"); + text_style.font_size = 26; + text_style.letter_spacing = 1; + text_style.word_spacing = 5; + text_style.color = SK_ColorBLACK; + text_style.height = 1; + text_style.decoration = TextDecoration::kUnderline; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = BuildParagraph(builder); + paragraph->Layout(GetTestCanvasWidth()); + + paragraph->Paint(GetCanvas(), 0, 0); + + ASSERT_TRUE(Snapshot()); + + // Tests for GetGlyphPositionAtCoordinate() + ASSERT_EQ( + paragraph->GetGlyphPositionAtCoordinate(GetTestCanvasWidth() - 0.5, 0.5) + .position, + 0ull); + + ASSERT_TRUE(Snapshot()); +} + TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) { const char* text = "This is a very long sentence to test if the text will properly wrap "