Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextPresenter is rendered before TemplateBinding of SelectionEnd to TextBox is updated when invoking SelectAll just after updating visibility #17530

Open
AngryCarrot789 opened this issue Nov 16, 2024 · 2 comments

Comments

@AngryCarrot789
Copy link

Describe the bug

From what I can tell, it seems like the TemplateBinding used to bind a TextBox's SelectionEnd property to the TextPresenter's SelectionEnd property does not get updated quickly enough when the TextBox's SelectionEnd changes, and as a result, the TextPresenter is rendered with a previous value.

To Reproduce

Set a TextBox's IsVisible property to true (when it was previously false), then set the Text to anything, then Focus() it and then invoke SelectAll(). It will select an amount of characters equal to I assume the length of the Text before IsVisible was set to false

Expected behavior

It should select the exact number of chars

Avalonia version

11.2.999-cibuild0048720-alpha

OS

Windows

Additional context

Here is a debug screenshot, the evaluator says the TextBox's selection end is 9, but the TextPresenter's is 5
image

@AngryCarrot789
Copy link
Author

Workaround:

textBox.Focus();
textBox.SelectAll();

TextPresenter? presenter = textBox.FindDescendantOfType<TextPresenter>(false);
if (presenter != null) {
    presenter.CoerceValue(TextPresenter.SelectionStartProperty);
    presenter.CoerceValue(TextPresenter.SelectionEndProperty);
}

@Gillibald
Copy link
Contributor

You are assuming text is also synced in time. I guess the TextPresenter still holds the old value. It was never a good idea to sync state via bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants