Skip to content

Commit 73271b4

Browse files
authored
Merge branch 'master' into fix/attached-property-name-generation
2 parents d090787 + 9d57ec0 commit 73271b4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public override CharacterHit GetCharacterHitFromDistance(double distance)
216216

217217
if (_paragraphProperties.FlowDirection == FlowDirection.LeftToRight)
218218
{
219-
currentPosition = lineLength - lastRun.Length;
219+
currentPosition = FirstTextSourceIndex + Length - lastRun.Length;
220220
}
221221

222222
return GetRunCharacterHit(lastRun, currentPosition, distance);

tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public void Should_Get_CharacterHit_For_Distance_With_TextEndOfLine()
713713

714714
var characterHit = textLine.GetCharacterHitFromDistance(1000);
715715

716-
Assert.Equal(10, characterHit.FirstCharacterIndex);
716+
Assert.Equal(11, characterHit.FirstCharacterIndex);
717717
Assert.Equal(1, characterHit.TrailingLength);
718718
}
719719
}
@@ -822,6 +822,26 @@ public void Should_GetPreviousCaretCharacterHit_From_Mixed_TextBuffer()
822822
}
823823
}
824824

825+
[Fact]
826+
public void Should_GetCharacterHitFromDistance_From_Mixed_TextBuffer()
827+
{
828+
using (Start())
829+
{
830+
var defaultProperties = new GenericTextRunProperties(Typeface.Default);
831+
var textSource = new MixedTextBufferTextSource();
832+
833+
var formatter = new TextFormatterImpl();
834+
835+
var textLine =
836+
formatter.FormatLine(textSource, 20, double.PositiveInfinity,
837+
new GenericTextParagraphProperties(defaultProperties));
838+
839+
var characterHit = textLine.GetCharacterHitFromDistance(double.PositiveInfinity);
840+
841+
Assert.Equal(40, characterHit.FirstCharacterIndex + characterHit.TrailingLength);
842+
}
843+
}
844+
825845
private class MixedTextBufferTextSource : ITextSource
826846
{
827847
public TextRun? GetTextRun(int textSourceIndex)

0 commit comments

Comments
 (0)