From bacb59bc0012e4c825d22482ec31f7c12833dcae Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Fri, 15 Mar 2024 11:29:14 +0100 Subject: [PATCH] Fix TextBox sync issues (#14960) * Sync change text and changed caret index with the TextPresenter when text input is handled * Do not add length again --- src/Avalonia.Controls/TextBox.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index c36b17b505..1292b332b1 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -1063,7 +1063,15 @@ namespace Avalonia.Controls _undoRedoHelper.DiscardRedo(); } - SetCurrentValue(CaretIndexProperty, caretIndex + input.Length); + //Make sure updated text is in sync + _presenter?.SetCurrentValue(TextPresenter.TextProperty, text); + + caretIndex += input.Length; + + //Make sure caret is in sync + _presenter?.MoveCaretToTextPosition(caretIndex); + + SetCurrentValue(CaretIndexProperty, caretIndex); } }