From 075aeecebf1694d4c35c27f75a164a9280e9f784 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 4 Nov 2019 15:59:17 +0000 Subject: [PATCH] fix skia formatted text impl hit testing. --- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index 718d10a694..dfdbfef136 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -102,12 +102,17 @@ namespace Avalonia.Skia AvaloniaFormattedTextLine line = default; - int i = 0; - - while(_skiaLines[i].Top < y && i < _skiaLines.Count) + foreach(var currentLine in _skiaLines) { - line = _skiaLines[i++]; - } + if(currentLine.Top <= y) + { + line = currentLine; + } + else + { + break; + } + } if (!line.Equals(default)) { @@ -135,12 +140,15 @@ namespace Avalonia.Skia line.Length : (line.Length - 1); } - return new TextHitTestResult + if (y < line.Top + line.Height) { - IsInside = false, - TextPosition = line.Start + offset, - IsTrailing = Text.Length == (line.Start + offset + 1) - }; + return new TextHitTestResult + { + IsInside = false, + TextPosition = line.Start + offset, + IsTrailing = Text.Length == (line.Start + offset + 1) + }; + } } bool end = point.X > _bounds.Width || point.Y > _lines.Sum(l => l.Height);