AvaloniaUI / AvaloniaEdit

Avalonia-based text editor (port of AvalonEdit)
MIT License
746 stars 148 forks source link

CompletionWindow doesn't work with mouse click #413

Closed NickRimmer closed 5 months ago

NickRimmer commented 5 months ago

Hey community,

I found strange behavior. When CompletionWindow opened, you can select variants by keyboard up/down and press enter - everything working as expected. But if you will open it and select option by mouse - it will just close CompletionWindow and do nothing.

How can we make it works by mouse selection as well?

How to reproduce

image

mgarstenauer commented 5 months ago

I looked at the code and found this TODO:

https://github.com/AvaloniaUI/AvaloniaEdit/blob/adbe72b8023207270d30c16beb4fadcd6d598023/src/AvaloniaEdit/CodeCompletion/CompletionList.cs#L190

Shouldn't be too hard to fix. Preparing a PR now...

What is the expected behavior? Do we want to insert the item on a single-click or a double-click? Most modern editors insert items with a single-click. IIRC, the original AvalonEdit used a double-click. I am going to implement single-click for now.

NickRimmer commented 5 months ago

Thank you so much for quick review @danipen. @MarchingCube thank you for great fix 🎉

gebodal commented 1 month ago

Apologies for being difficult, resurrecting an old issue, but it would be great if the single/double click was configurable somehow. There doesn't seem to be a particularly clean way of overloading these classes to change the behaviour, as the AddHandler(...) is embedded in the class constructor, so an option would be great.

mgarstenauer commented 1 month ago

What would be the motivation for using double-click instead of single-click?

gebodal commented 1 month ago

The motivation for me would be that the ListBox is a SelectingItemsControl, and the fact that the selection works with the arrow keys but not the mouse pointer breaks the affordance (had to look up the technical term there) of the control. It also doesn't seem consistent across the various interactions. And, as the action now triggers on PointerPressed rather than PointerReleased or DoubleTapped, the action occurs sooner than expected, which slightly diminishes recoverability for user input.

As an example, Visual Studio uses a single-click for selecting items in the autocomplete dropdown, and double-click for activating a given autocomplete option.

mgarstenauer commented 1 month ago

I'll look into it.

mgarstenauer commented 1 month ago

@gebodal I don't see a simple way to support DoubleTapped. The ListBoxItem consumes the first click when it is not selected. The DoubleTapped event (or PointerPressedEvent with ClickCount == 2) only fires when the ListBoxItem is already selected. That means, you would need to triple-click in most cases.

The current implementation (PointerPressed) behaves the same as ReSharper or VS Code. Perhaps there is an simple way to make DoubleTapped work as well, but I am not aware of it.

mgarstenauer commented 1 month ago

After further digging: I was wrong about the ListBoxItem. It does not prevent the DoubleTapped event from being fired. Showing the completion item's tool-tip prevents the DoubleTapped event from being fired. (Opening the PopupWithCustomPosition seems to reset the double-click logic.)

mgarstenauer commented 1 month ago

Had some time today to look at this again and found a solution. There is now an option to choose whether to insert the completion item on PointerPressed, PointerReleased, or DoubleTapped.

@gebodal Can you test #451?