Browse Source

Fix caret handles not updating to the latest caret points (#18794)

* fix caret handles not updating to the latest caret points

* Update TextSelectionCanvas.cs
release/11.3.1
Emmanuel Hansen 9 months ago
committed by Julien Lebosquain
parent
commit
933e1bc2c4
  1. 8
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  2. 31
      src/Avalonia.Controls/Primitives/TextSelectionCanvas.cs

8
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -455,14 +455,14 @@ namespace Avalonia.Controls.Presenters
internal (Point, Point) GetCaretPoints()
{
var x = Math.Floor(_caretBounds.X) + 0.5;
var y = Math.Floor(_caretBounds.Y) + 0.5;
var b = Math.Ceiling(_caretBounds.Bottom) - 0.5;
var caretIndex = _lastCharacterHit.FirstCharacterIndex + _lastCharacterHit.TrailingLength;
var lineIndex = TextLayout.GetLineIndexFromCharacterIndex(caretIndex, _lastCharacterHit.TrailingLength > 0);
var textLine = TextLayout.TextLines[lineIndex];
var x = Math.Floor(_caretBounds.X) + 0.5;
var y = Math.Floor(_caretBounds.Y) + 0.5;
var b = Math.Ceiling(_caretBounds.Bottom) - 0.5;
if (_caretBounds.X > 0 && _caretBounds.X >= textLine.WidthIncludingTrailingWhitespace)
{
x -= 1;

31
src/Avalonia.Controls/Primitives/TextSelectionCanvas.cs

@ -262,6 +262,21 @@ namespace Avalonia.Controls.Primitives
{
if (_presenter == textPresenter)
return;
if (_textBox != null)
{
_textBox.RemoveHandler(TextBox.TextChangingEvent, TextChanged);
_textBox.RemoveHandler(KeyDownEvent, TextBoxKeyDown);
_textBox.RemoveHandler(PointerReleasedEvent, TextBoxPointerReleased);
_textBox.RemoveHandler(Gestures.HoldingEvent, TextBoxHolding);
_textBox.PropertyChanged -= TextBoxPropertyChanged;
_textBox.EffectiveViewportChanged -= TextBoxEffectiveViewportChanged;
_textBox.SizeChanged -= TextBox_SizeChanged;
_textBox = null;
}
_presenter = textPresenter;
if (_presenter != null)
{
@ -279,22 +294,6 @@ namespace Avalonia.Controls.Primitives
_textBox.SizeChanged += TextBox_SizeChanged;
}
}
else
{
if (_textBox != null)
{
_textBox.RemoveHandler(TextBox.TextChangingEvent, TextChanged);
_textBox.RemoveHandler(KeyDownEvent, TextBoxKeyDown);
_textBox.RemoveHandler(PointerReleasedEvent, TextBoxPointerReleased);
_textBox.RemoveHandler(Gestures.HoldingEvent, TextBoxHolding);
_textBox.PropertyChanged -= TextBoxPropertyChanged;
_textBox.EffectiveViewportChanged -= TextBoxEffectiveViewportChanged;
_textBox.SizeChanged -= TextBox_SizeChanged;
}
_textBox = null;
}
}
private void TextBox_SizeChanged(object? sender, SizeChangedEventArgs e)

Loading…
Cancel
Save