From 3b23aa2f079b0d2db7a5e5e4fe248c9abc1bf9b6 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Fri, 30 Jun 2023 21:53:59 +0200 Subject: [PATCH] Enforce that TextBox and TextPresenter are in sync when SurroundingText is requested --- src/Avalonia.Controls/TextBoxTextInputMethodClient.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/TextBoxTextInputMethodClient.cs b/src/Avalonia.Controls/TextBoxTextInputMethodClient.cs index 3c86471fbb..66581df3be 100644 --- a/src/Avalonia.Controls/TextBoxTextInputMethodClient.cs +++ b/src/Avalonia.Controls/TextBoxTextInputMethodClient.cs @@ -25,15 +25,14 @@ namespace Avalonia.Controls #if DEBUG if (_parent.CaretIndex != _presenter.CaretIndex) { - throw new InvalidOperationException("TextBox and TextPresenter are out of sync"); + _presenter.SetCurrentValue(TextPresenter.CaretIndexProperty, _parent.CaretIndex); } if (_parent.Text != _presenter.Text) { - throw new InvalidOperationException("TextBox and TextPresenter are out of sync"); + _presenter.SetCurrentValue(TextPresenter.TextProperty, _parent.Text); } #endif - var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(_presenter.CaretIndex, false); var textLine = _presenter.TextLayout.TextLines[lineIndex];