Skip to content

Fix: Fixed issue with focusing file list using touch #15054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using Windows.System;
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
Expand Down Expand Up @@ -41,18 +38,14 @@ public RectangleSelection_ListViewBase(ListViewBase uiElement, Rectangle selecti
private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (scrollViewer is null)
{
return;
}

var currentPoint = e.GetCurrentPoint(uiElement);
var verticalOffset = scrollViewer.VerticalOffset;
if (selectionState == SelectionState.Starting)
{
if (!HasMovedMinimalDelta(originDragPoint.X, originDragPoint.Y - verticalOffset, currentPoint.Position.X, currentPoint.Position.Y))
{
return;
}

// Clear selected items once if the pointer is pressed and moved
selectionStrategy.StartSelection();
Expand All @@ -73,13 +66,9 @@ private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventAr
try
{
if (rect.IntersectsWith(item.Value))
{
selectionStrategy.HandleIntersectionWithItem(item.Key);
}
else
{
selectionStrategy.HandleNoIntersectionWithItem(item.Key);
}
}
catch (ArgumentException)
{
Expand Down Expand Up @@ -131,9 +120,9 @@ private void RectangleSelection_PointerPressed(object sender, PointerRoutedEvent

var verticalOffset = scrollViewer.VerticalOffset;
originDragPoint.Y += verticalOffset; // Initial drag point relative to the top of the list (considering scrolled offset)
if (!e.GetCurrentPoint(uiElement).Properties.IsLeftButtonPressed || e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Touch)
if (!e.GetCurrentPoint(uiElement).Properties.IsLeftButtonPressed && e.Pointer.PointerDeviceType != Microsoft.UI.Input.PointerDeviceType.Touch)
{
// Trigger only on left click, do not trigger with touch
// Trigger only on left click or with a tap
return;
}

Expand All @@ -147,13 +136,17 @@ private void RectangleSelection_PointerPressed(object sender, PointerRoutedEvent

selectionStrategy.HandleNoItemSelected();

uiElement.PointerMoved -= RectangleSelection_PointerMoved;
uiElement.PointerMoved += RectangleSelection_PointerMoved;
if (selectionChanged is not null)
// Don't hook events for touch
if (e.Pointer.PointerDeviceType != Microsoft.UI.Input.PointerDeviceType.Touch)
{
// Unsunscribe from SelectionChanged event for performance
uiElement.SelectionChanged -= selectionChanged;
uiElement.PointerMoved -= RectangleSelection_PointerMoved;
uiElement.PointerMoved += RectangleSelection_PointerMoved;
}

// Unsunscribe from SelectionChanged event for performance
if (selectionChanged is not null)
uiElement.SelectionChanged -= selectionChanged;

uiElement.CapturePointer(e.Pointer);
selectionState = SelectionState.Starting;
}
Expand Down Expand Up @@ -186,31 +179,34 @@ private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEven

private void RectangleSelection_PointerReleased(object sender, PointerRoutedEventArgs e)
{
if (scrollViewer is null) return;
if (scrollViewer is null)
return;

// Reset selection rectangle
Canvas.SetLeft(selectionRectangle, 0);
Canvas.SetTop(selectionRectangle, 0);
selectionRectangle.Width = 0;
selectionRectangle.Height = 0;
uiElement.PointerMoved -= RectangleSelection_PointerMoved;

// Unhook events
uiElement.PointerMoved -= RectangleSelection_PointerMoved;
scrollViewer.ViewChanged -= ScrollViewer_ViewChanged;

uiElement.ReleasePointerCapture(e.Pointer);
if (selectionChanged is not null)
{
// Restore and trigger SelectionChanged event
uiElement.SelectionChanged -= selectionChanged;
uiElement.SelectionChanged += selectionChanged;

// Trigger SelectionChanged event if the selection has changed
if (prevSelectedItems is null || !uiElement.SelectedItems.SequenceEqual(prevSelectedItems))
{
// Trigger SelectionChanged event if the selection has changed
selectionChanged(sender, null);
}
}

// Always trigger SelectionEnded to focus the file list when clicking on the empty space (#2977)
if (selectionState == SelectionState.Active || e.OriginalSource is ListViewBase)
{
// Always trigger SelectionEnded to focus the file list when clicking on the empty space (#2977)
OnSelectionEnded();
}

selectionStrategy = null;
selectionState = SelectionState.Inactive;
Expand All @@ -225,9 +221,7 @@ private void RectangleSelection_SizeChanged(object sender, object e)
scrollViewer ??= DependencyObjectHelpers.FindChild<ScrollViewer>(uiElement, sv => sv.VerticalScrollMode != ScrollMode.Disabled);

if (scrollViewer is not null)
{
uiElement.SizeChanged -= RectangleSelection_SizeChanged;
}
}

private void InitEvents(object sender, RoutedEventArgs e)
Expand All @@ -246,10 +240,8 @@ private void InitEvents(object sender, RoutedEventArgs e)

scrollViewer = DependencyObjectHelpers.FindChild<ScrollViewer>(uiElement, sv => sv.VerticalScrollMode != ScrollMode.Disabled);
if (scrollViewer is null)
{
uiElement.SizeChanged += RectangleSelection_SizeChanged;
}
}
}
}
}
}