Skip to content

Commit

Permalink
Merge pull request #12322 from Gillibald/fixes/getCharacterHitFromDis…
Browse files Browse the repository at this point in the history
…tance

Adjust GetCharacterHitFromDistance to match what WPF expects
  • Loading branch information
Dan Walmsley authored Jul 25, 2023
2 parents fc12649 + b6489e0 commit 40afe1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public override CharacterHit GetCharacterHitFromDistance(double distance)

if (_paragraphProperties.FlowDirection == FlowDirection.RightToLeft)
{
currentPosition = Length - firstRun.Length;
currentPosition += lineLength - firstRun.Length;
}

return GetRunCharacterHit(firstRun, currentPosition, 0);
Expand All @@ -216,7 +216,7 @@ public override CharacterHit GetCharacterHitFromDistance(double distance)

if (_paragraphProperties.FlowDirection == FlowDirection.LeftToRight)
{
currentPosition = FirstTextSourceIndex + Length - lastRun.Length;
currentPosition += lineLength - lastRun.Length;
}

return GetRunCharacterHit(lastRun, currentPosition, distance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public void Should_Get_CharacterHit_For_Distance_With_TextEndOfLine()

var characterHit = textLine.GetCharacterHitFromDistance(1000);

Assert.Equal(11, characterHit.FirstCharacterIndex);
Assert.Equal(10, characterHit.FirstCharacterIndex);
Assert.Equal(1, characterHit.TrailingLength);
}
}
Expand Down

0 comments on commit 40afe1b

Please sign in to comment.