Avalonia: TextBox doesn't bring typed character into view when overflowing

Created on 5 Oct 2019  路  10Comments  路  Source: AvaloniaUI/Avalonia

On Windows 10, using .NET Core 3.0, TextBox does not properly scroll the most recently typed character into view when the contents are too long. Pressing <Right Arrow> does not affect anything, and continuing to type will cause the second to last character to come into view. Pressing <Left Arrow> will cause the end of the text to pop back into view.

Update: I tested on Ubuntu 19.04 and it has the same issue there as well, so it does not appear to be platform-specific.

Steps to reproduce:

  1. Create a new project with dotnet new avalonia.app -o aui-bug
  2. Open MainWindow.xaml and replace the default text with <TextBox Height="26" Width="100" />
  3. Run the program
  4. Type in the TextBox until the text reaches the end
  5. Continue typing

Expected result:
When a character is typed, the contents of the TextBox should scroll to the left, with the newly typed character and the carat in view.

Actual result:
When a character is typed right as the contents are about to overflow, the text does not move, the carat moves out of view and the newly typed character is entered "off screen". Subsequent characters cause the text to scroll to the left, but only enough for the second-to-last character to be visible.

bug

Most helpful comment

All 10 comments

I don't think that the TextBox should scroll if you reach the maximum width and height. Only when the text is measured with infinite space you get the expected result.

@gillibald i don't understand how that relates to the issue. Could you explain?

The text layout is limited by the constraint passed to it. When you set the width explicitly the text isn't measured with infinite width and therefore isn't rendered properly. We could ignore the constraint when we have no wrapping.

Update:

Looks like we already measure FormattedText with infinite space so this is a bug. https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/TextBlock.cs#L389

Will have a look what goes wrong.

With the new layout I don't see such behavior when I last checked the ControlCatalog.

I only set the width and height in my example to make it easier to reproduce because otherwise the TextBox expands to fill the entire window and you have to enter more text to reach the right side, but the behavior is the same without it.

Standard text box behavior is to keep the caret in view.

The issue is that the constraint is cached. So FormattedText can't expand during the TextBox's lifetime. Will have a look how to remove this behavior.

Possible duplicate of #2723

@Gillibald No, that one is talking about auto-sizing text boxes not resizing properly.

This is definitely a regression. Taking a look.

Problem seems to be here: https://github.com/AvaloniaUI/Avalonia/blob/04e2e460d2887c5262319556e5571fb9a9d59521/src/Avalonia.Controls/Presenters/TextPresenter.cs#L241-L247

The inner HitTest/BringIntoView runs before the measure has actually taken place. Dispatcher priority needs to be set to something lower than Layout.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitHubington picture GitHubington  路  3Comments

khoshroomahdi picture khoshroomahdi  路  4Comments

CreateLab picture CreateLab  路  3Comments

x2bool picture x2bool  路  4Comments

TheColonel2688 picture TheColonel2688  路  3Comments