AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.29k stars 2.19k forks source link

Text selection works incorrectly for TextBoxes in adorner layer #15480

Open BAndysc opened 4 months ago

BAndysc commented 4 months ago

Describe the bug

When a TextBox is attached as an adorner, then text selection doesn't work correctly - it ignores the placement of the adorned element.

https://github.com/AvaloniaUI/Avalonia/assets/5689666/497fcaba-7237-412b-a211-1d5205e9c876

To Reproduce

  1. git clone https://github.com/BAndysc/avalonia-bugs-repro
  2. git checkout bug_textbox_selection_adorner
  3. Try to select the text in textbox

Expected behavior

No response

Avalonia version

11.0.10, 11.1

OS

No response

Additional context

No response

BAndysc commented 4 months ago

Unfortunately it is related to https://github.com/AvaloniaUI/Avalonia/pull/14439

PointerEventArgs uses TransformToVisual extension to calculate press position

https://github.com/AvaloniaUI/Avalonia/blob/fcea3453ff62225c4be56cf2569edffc72e7402e/src/Avalonia.Base/Input/PointerEventArgs.cs#L97

but TransformToVisual doesn't work with Adorners :( sadly, adorners are defined in another assembly (Avalonia.Controls), TransformToVisual is in Avalonia.Base so this method can't be easily modified to take into account adorners

maoyy commented 1 week ago

I have also encountered this problem and look forward to fixing it soon