diff --git a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs index 277c7bdac103..8da43d3ad83f 100644 --- a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs +++ b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs @@ -36,10 +36,14 @@ public sealed partial class ColumnViewBase : StandardViewBase private ListViewItem? openedFolderPresenter; + // Indicates if the selection rectangle is currently being dragged + private bool isDraggingSelectionRectangle = false; + public ColumnViewBase() : base() { InitializeComponent(); var selectionRectangle = RectangleSelection.Create(FileList, SelectionRectangle, FileList_SelectionChanged); + selectionRectangle.SelectionStarted += SelectionRectangle_SelectionStarted; selectionRectangle.SelectionEnded += SelectionRectangle_SelectionEnded; ItemInvoked += ColumnViewBase_ItemInvoked; GotFocus += ColumnViewBase_GotFocus; @@ -211,17 +215,29 @@ protected override void FileList_SelectionChanged(object sender, SelectionChange presenter!.Background = this.Resources["ListViewItemBackgroundSelected"] as SolidColorBrush; } - if (SelectedItems?.Count == 1 && SelectedItem?.PrimaryItemAttribute is StorageItemTypes.Folder && openedFolderPresenter != FileList.ContainerFromItem(SelectedItem)) + if (SelectedItems?.Count == 1 && SelectedItem?.PrimaryItemAttribute is StorageItemTypes.Folder) { - if (UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick) + // // Prevents the first selected folder from opening if the user is currently dragging the selection rectangle (#13418) + if (isDraggingSelectionRectangle) + { + CloseFolder(); + return; + } + + if (openedFolderPresenter == FileList.ContainerFromItem(SelectedItem)) + return; + + // Open the selected folder if selected through tap + if (UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick && !isDraggingSelectionRectangle) ItemInvoked?.Invoke(new ColumnParam { Source = this, NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty); else CloseFolder(); } else if (SelectedItems?.Count > 1 || SelectedItem?.PrimaryItemAttribute is StorageItemTypes.File - || openedFolderPresenter != null && ParentShellPageInstance != null && - !ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.Contains(FileList.ItemFromContainer(openedFolderPresenter))) + || openedFolderPresenter != null && ParentShellPageInstance != null + && !ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.Contains(FileList.ItemFromContainer(openedFolderPresenter)) + && !isDraggingSelectionRectangle) // Skip closing if dragging since nothing should be open { CloseFolder(); } @@ -482,6 +498,23 @@ protected override void BaseFolderSettings_LayoutModeChangeRequested(object? sen } } + protected override void SelectionRectangle_SelectionEnded(object? sender, EventArgs e) + { + isDraggingSelectionRectangle = false; + // Open selected folder (if only one folder is selected) after the user finishes dragging the selection rectangle + if (SelectedItems?.Count is 1 + && SelectedItem is not null + && SelectedItem.PrimaryItemAttribute is StorageItemTypes.Folder) + ItemInvoked?.Invoke(new ColumnParam { Source = this, NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty); + + base.SelectionRectangle_SelectionEnded(sender, e); + } + + private void SelectionRectangle_SelectionStarted(object sender, EventArgs e) + { + isDraggingSelectionRectangle = true; + } + internal void ClearSelectionIndicator() { LockPreviewPaneContent = true;