textLine.GetNextCaretCharacterHit fails for certain input
See original GitHub issueGetting the next caret hit fails for certain inputs. The expected behaviour is to just return the right most trailing character hit of the cursor can’t move further to the right/ the left most leading char hit if the cursor can’t move further to the left.
This works as expected mostly but throws for certain inputs.
Test that reproduces the issue on 0.10.999-cibuild0011450-beta
.
in TextLineTests.cs
[InlineData("𐐷𐐷𐐷𐐷𐐷")] // works
[InlineData("01234567🎉\n")] // fails
[Theory]
public void Should_Get_Next_Caret_CharacterHits_And_Stop_At_Last_One(string text)
{
using (Start())
{
var defaultProperties = new GenericTextRunProperties(Typeface.Default);
var textSource = new SingleBufferTextSource(text, defaultProperties);
var textLine =
TextFormatter.Current.FormatLine(textSource, 0, double.PositiveInfinity,
new GenericTextParagraphProperties(defaultProperties, lineHeight: double.NaN));
var currentHit = new CharacterHit(0, 0);
foreach (var _ in Enumerable.Range(0, 20))
{
var input = new CharacterHit(currentHit.FirstCharacterIndex, 0);
var nextHit = textLine.GetNextCaretCharacterHit(input);
currentHit = nextHit;
Console.WriteLine($"input char hit ({input.FirstCharacterIndex}, {input.TrailingLength}) -> output char hit ({nextHit.FirstCharacterIndex}, {nextHit.TrailingLength})");
}
}
}
fails with
System.IndexOutOfRangeException: Index was outside the bounds of the array.
System.IndexOutOfRangeException
Index was outside the bounds of the array.
at Avalonia.Utilities.ReadOnlySlice`1.get_Item(Int32 index)
at Avalonia.Media.TextFormatting.Unicode.Codepoint.ReadAt(ReadOnlySlice`1 text, Int32 index, Int32& count)
at Avalonia.Media.TextFormatting.TextLineImpl.TryFindNextCharacterHit(CharacterHit characterHit, CharacterHit& nextCharacterHit)
at Avalonia.Media.TextFormatting.TextLineImpl.GetNextCaretCharacterHit(CharacterHit characterHit)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
I'm getting an error message when I text a contact
Go to the Contact's profile page to see if re-subscribing them is an option. Make sure to have their consent before re-subscribing them...
Read more >10.43. Text Input Problem - Open edX documentation
In text input problems, learners enter text into a response field. The response can include numbers, letters, and special characters such as punctuation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes this is fixed in the FormattedText branch. The moment I have fixed the remaining issues in that branch I will try to merge it into master. All the changes to TextFormatter etc. will improve your ability to write an editor.
This PR improves the TextLine API to deal with trailing whitespace https://github.com/AvaloniaUI/Avalonia/pull/4893 Trying to fix this for master