Skip to content

RightToLeft RichTextBlock: clicking a drawn Hyperlink does nothing, hit-testing ignores the RTL alignment flipΒ #24748

Open

Description

@MartinZikmund

Current behavior πŸ›

In a RichTextBlock with FlowDirection="RightToLeft", a short line is drawn right-aligned (correct), but pointer hit-testing still treats the line as left-aligned:

  • clicking the drawn Hyperlink does nothing,
  • clicking the empty space on the left, where the link would be if the line were left-aligned, raises Hyperlink.Click.

Selection and hover use the same hit-test path (ParsedText.GetIndexAt), so they pick characters from the mirrored position as well (by code inspection).

Measured on Skia Desktop (Windows), Width="300", FontSize="24":

Content Link drawn at x Click on drawn link Click on mirrored empty spot
LTR, Link 3..45 Click raised no Click
RTL, Link 257..299 no Click Click raised
RTL, Ψ±Ψ§Ψ¨Ψ· 259..297 no Click Click raised

TextBlock is not affected: it renders through a different engine whose drawing and hit-testing share one alignment offset, so its hyperlinks are clickable where they are drawn.

Expected behavior 🎯

Clicking the drawn hyperlink raises Click, and clicking empty space does not, as in WinUI.

WinUI draws the same content at the right edge (native WinUI runtime check with the same test: RTL RichTextBlock link ink at x 260..299 for Link, 258..297 for Ψ±Ψ§Ψ¨Ψ·), and its hit-testing uses the same line offset that arrange/render computed: ParagraphNode::PixelPositionToTextPosition subtracts lineMetrics.Rect.X, which ParagraphNode::ArrangeCore set from CalculateLineOffset (ParagraphNode.cpp L294, L705).

How to reproduce it (as minimally and precisely as possible) πŸ”¬

  1. Add to any page and run on a Skia head:
    <RichTextBlock Width="300" FontSize="24" FlowDirection="RightToLeft"
                   HorizontalAlignment="Left" Background="White">
        <Paragraph>
            <Hyperlink x:Name="Link" Click="OnLinkClick" UnderlineStyle="None">Link</Hyperlink>
        </Paragraph>
    </RichTextBlock>
    private void OnLinkClick(Hyperlink sender, HyperlinkClickEventArgs args) => System.Diagnostics.Debug.WriteLine("Clicked");
  2. "Link" is drawn at the right edge of the 300px box. Click it: nothing is logged.
  3. Click the empty area at the left edge of the box, roughly the same distance from the left as the link is from the right: "Clicked" is logged.

Runtime test (Skia Desktop) that reproduces it with injected input:

[TestMethod]
[DataRow(false, false)]
[DataRow(true, false)]
[DataRow(true, true)]
public async Task When_RichTextBlock_RTL_Click_Drawn_Hyperlink(bool rtl, bool arabic)
{
	var hyperlink = new Hyperlink { Foreground = new SolidColorBrush(Colors.Red), UnderlineStyle = UnderlineStyle.None };
	hyperlink.Inlines.Add(new Run { Text = arabic ? "Ψ±Ψ§Ψ¨Ψ·" : "Link" });
	var rtb = new RichTextBlock { Width = 300, FontSize = 24, FlowDirection = rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight };
	var para = new Paragraph();
	para.Inlines.Add(hyperlink);
	rtb.Blocks.Add(para);

	var clicks = 0;
	hyperlink.Click += (_, _) => clicks++;
	var host = new Border { Background = new SolidColorBrush(Colors.White), Child = rtb, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top };
	await UITestHelper.Load(host);

	// Locate the drawn (red) link.
	var bitmap = await UITestHelper.ScreenShot(host);
	int minX = int.MaxValue, maxX = -1, minY = int.MaxValue, maxY = -1;
	for (var y = 0; y < bitmap.Height; y++)
	{
		for (var x = 0; x < bitmap.Width; x++)
		{
			var c = bitmap.GetPixel(x, y);
			if (c.R > 180 && c.G < 120 && c.B < 120)
			{
				minX = Math.Min(minX, x); maxX = Math.Max(maxX, x);
				minY = Math.Min(minY, y); maxY = Math.Max(maxY, y);
			}
		}
	}

	var bounds = host.GetAbsoluteBounds();
	var drawn = new Point(bounds.X + (minX + maxX) / 2.0, bounds.Y + (minY + maxY) / 2.0);
	var mirrored = new Point(bounds.X + bounds.Width - (minX + maxX) / 2.0, drawn.Y);

	var injector = InputInjector.TryCreate()!;
	using var mouse = injector.GetMouse();
	mouse.MoveTo(drawn); await WindowHelper.WaitForIdle();
	mouse.Press(); mouse.Release(); await WindowHelper.WaitForIdle();
	var clicksOnDrawn = clicks;

	mouse.MoveTo(new Point(bounds.X + bounds.Width / 2, bounds.Bottom + 50)); await WindowHelper.WaitForIdle();
	mouse.MoveTo(mirrored); await WindowHelper.WaitForIdle();
	mouse.Press(); mouse.Release(); await WindowHelper.WaitForIdle();

	Assert.AreEqual(1, clicksOnDrawn, "Click on the drawn hyperlink should raise Click");     // fails for RTL
	Assert.AreEqual(0, clicks - clicksOnDrawn, "Click on empty space should not raise Click"); // fails for RTL
}

The LTR case passes and both RTL cases fail.

Workaround πŸ› οΈ

Use FlowDirection="LeftToRight" with TextAlignment="Right" where the text itself doesn't need an RTL paragraph, or keep hyperlinks on lines that fill the whole width.

Renderer 🎨

  • Skia
  • Native

Affected platforms πŸ“±πŸ’»πŸ–₯️

Desktop (Windows), Desktop (macOS), Desktop (X11), WebAssembly, Android, iOS

Uno.Sdk version (and other relevant versions) πŸ“¦

master at ffcff32 (7.0 dev). Reproduced on Skia Desktop (Windows) with net11.0-desktop.

IDE version πŸ§‘β€πŸ’»

No response

Anything else we need to know? πŸ’¬

Root cause. RTL text surfaces are not mirrored as elements (UIElement.cs L116-L121), so the text engine has to do the RTL flip itself and pointer positions arrive in physical coordinates. ParsedText.Draw does the flip, swapping Left/Right before computing the line offset (ParsedText.cs L530-L539). The hit-test paths call line.GetOffsets with the unswapped ResolvedTextAlignment:

  • GetRectForIndex (L832)
  • GetRenderSegmentSpanAt, used by GetIndexAt / GetHyperlinkAt (L1417)

RichTextBlock.FindHyperlinkAtSkia and GetCharacterIndexAtPointSkia pass the raw pointer position into these (RichTextBlock.mux.cs L672-L719).

Suggested fix. Resolve the effective drawing alignment (RTL swap included) in one helper and use it in Draw, GetRectForIndex and GetRenderSegmentSpanAt, so drawing and hit-testing can't diverge. It is also worth checking that the hit-test walk over RTL segments uses the same visual order as Draw.

Activity

  1. added
    kind/bug
    triage/untriaged
    area/skia ✏️
    project/pointers πŸ–±οΈ
    project/text πŸ”€
    platform/all
    difficulty/medium πŸ€”
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/skia ✏️area/skia/text ✏️difficulty/medium πŸ€”kind/bugplatform/allproject/pointers πŸ–±οΈproject/text πŸ”€triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions