Skip to content

Commit

Permalink
fix(listview): add support for Ctrl+Click unselecting
Browse files Browse the repository at this point in the history
(cherry picked from commit 953ac58)
  • Loading branch information
ramezgerges authored and mergify[bot] committed Aug 4, 2023
1 parent afaf0a4 commit e161fae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ partial void OnSelectionModeChangedPartial(ListViewSelectionMode oldSelectionMod



internal override void OnItemClicked(int clickedIndex)
internal override void OnItemClicked(int clickedIndex, VirtualKeyModifiers modifiers)
{
// Note: don't call base.OnItemClicked(), because we override the default single-selection-only handling

Expand Down Expand Up @@ -487,7 +487,16 @@ internal override void OnItemClicked(int clickedIndex)
// The CollectionView may have intercepted the change
clickedIndex = collectionView.CurrentPosition;
}
SelectedIndex = clickedIndex;

if ((modifiers & VirtualKeyModifiers.Control) != 0 && clickedIndex == SelectedIndex)
{
SelectedIndex = -1;
}
else
{
SelectedIndex = clickedIndex;
}

break;
case ListViewSelectionMode.Multiple:
case ListViewSelectionMode.Extended:
Expand Down
7 changes: 5 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Primitives/Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Windows.UI.Xaml.Data;
using Uno.UI.DataBinding;
using Windows.Foundation.Collections;
using Windows.System;
using Uno.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

Expand Down Expand Up @@ -555,9 +556,11 @@ internal override void OnItemsSourceGroupsChanged(object sender, NotifyCollectio
}
}

internal void OnItemClicked(SelectorItem selectorItem) => OnItemClicked(IndexFromContainer(selectorItem));
internal void OnItemClicked(SelectorItem selectorItem, VirtualKeyModifiers modifiers) => OnItemClicked(IndexFromContainer(selectorItem), modifiers);

internal virtual void OnItemClicked(int clickedIndex)
internal virtual void OnItemClicked(int clickedIndex) => OnItemClicked(clickedIndex, VirtualKeyModifiers.None);

internal virtual void OnItemClicked(int clickedIndex, VirtualKeyModifiers modifiers)
{
if (ItemsSource is ICollectionView collectionView)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Primitives/SelectorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected override void OnPointerReleased(PointerRoutedEventArgs args)
_canRaiseClickOnPointerRelease = false;

update = ManipulationUpdateKind.Clicked;
Selector?.OnItemClicked(this);
Selector?.OnItemClicked(this, args.KeyModifiers);

// This should be automatically done by the pointers due to release, but if for any reason
// the state is invalid, this makes sure to not keep invalid capture longer than needed.
Expand Down

0 comments on commit e161fae

Please sign in to comment.