Browse Source

Merge pull request #12322 from Gillibald/fixes/getCharacterHitFromDistance

Adjust GetCharacterHitFromDistance to match what WPF expects
release/11.0.1
Dan Walmsley 3 years ago
committed by GitHub
parent
commit
40afe1b574
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  2. 2
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

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

@ -204,7 +204,7 @@ namespace Avalonia.Media.TextFormatting
if (_paragraphProperties.FlowDirection == FlowDirection.RightToLeft) if (_paragraphProperties.FlowDirection == FlowDirection.RightToLeft)
{ {
currentPosition = Length - firstRun.Length; currentPosition += lineLength - firstRun.Length;
} }
return GetRunCharacterHit(firstRun, currentPosition, 0); return GetRunCharacterHit(firstRun, currentPosition, 0);
@ -216,7 +216,7 @@ namespace Avalonia.Media.TextFormatting
if (_paragraphProperties.FlowDirection == FlowDirection.LeftToRight) if (_paragraphProperties.FlowDirection == FlowDirection.LeftToRight)
{ {
currentPosition = FirstTextSourceIndex + Length - lastRun.Length; currentPosition += lineLength - lastRun.Length;
} }
return GetRunCharacterHit(lastRun, currentPosition, distance); return GetRunCharacterHit(lastRun, currentPosition, distance);

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

@ -713,7 +713,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
var characterHit = textLine.GetCharacterHitFromDistance(1000); var characterHit = textLine.GetCharacterHitFromDistance(1000);
Assert.Equal(11, characterHit.FirstCharacterIndex); Assert.Equal(10, characterHit.FirstCharacterIndex);
Assert.Equal(1, characterHit.TrailingLength); Assert.Equal(1, characterHit.TrailingLength);
} }
} }

Loading…
Cancel
Save