question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

textLine.GetNextCaretCharacterHit fails for certain input

See original GitHub issue

Getting 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:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Gillibaldcommented, Dec 16, 2020

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.

1reaction
Gillibaldcommented, Dec 3, 2020

This PR improves the TextLine API to deal with trailing whitespace https://github.com/AvaloniaUI/Avalonia/pull/4893 Trying to fix this for master

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found