Skip to content

Commit 2dfdd3f

Browse files
authored
Fix: Fixed an issue where the file area would sometimes lose focus when opening a folder (#13130)
1 parent 65b2519 commit 2dfdd3f

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/Files.App/Data/Models/ItemViewModel.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ void ClearDisplay()
616616

617617
return;
618618
}
619+
var filesAndFoldersLocal = filesAndFolders.ToList();
619620

620621
// CollectionChanged will cause UI update, which may cause significant performance degradation,
621622
// so suppress CollectionChanged event here while loading items heavily.
@@ -643,19 +644,19 @@ void ApplyBulkInsertEntries()
643644
}
644645
}
645646

646-
for (var i = 0; i < filesAndFolders.Count; i++)
647+
for (var i = 0; i < filesAndFoldersLocal.Count; i++)
647648
{
648649
if (addFilesCTS.IsCancellationRequested)
649650
return;
650651

651652
if (i < FilesAndFolders.Count)
652653
{
653-
if (FilesAndFolders[i] != filesAndFolders[i])
654+
if (FilesAndFolders[i] != filesAndFoldersLocal[i])
654655
{
655656
if (startIndex == -1)
656657
startIndex = i;
657658

658-
tempList.Add(filesAndFolders[i]);
659+
tempList.Add(filesAndFoldersLocal[i]);
659660
}
660661
else
661662
{
@@ -665,16 +666,16 @@ void ApplyBulkInsertEntries()
665666
else
666667
{
667668
ApplyBulkInsertEntries();
668-
FilesAndFolders.InsertRange(i, filesAndFolders.ToList().Skip(i));
669+
FilesAndFolders.InsertRange(i, filesAndFoldersLocal.Skip(i));
669670

670671
break;
671672
}
672673
}
673674

674675
ApplyBulkInsertEntries();
675676

676-
if (FilesAndFolders.Count > filesAndFolders.Count)
677-
FilesAndFolders.RemoveRange(filesAndFolders.Count, FilesAndFolders.Count - filesAndFolders.Count);
677+
if (FilesAndFolders.Count > filesAndFoldersLocal.Count)
678+
FilesAndFolders.RemoveRange(filesAndFoldersLocal.Count, FilesAndFolders.Count - filesAndFoldersLocal.Count);
678679

679680
if (folderSettings.DirectoryGroupOption != GroupOption.None)
680681
OrderGroups();
@@ -1638,9 +1639,9 @@ await Task.Run(async () =>
16381639

16391640
filesAndFolders.AddRange(fileList);
16401641

1641-
await dispatcherQueue.EnqueueOrInvokeAsync(CheckForSolutionFile, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
16421642
await OrderFilesAndFoldersAsync();
16431643
await ApplyFilesAndFoldersChangesAsync();
1644+
await dispatcherQueue.EnqueueOrInvokeAsync(CheckForSolutionFile, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
16441645
});
16451646

16461647
rootFolder ??= await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path));
@@ -1688,16 +1689,9 @@ await Task.Run(async () =>
16881689

16891690
private void CheckForSolutionFile()
16901691
{
1691-
for (int i = 0; i < filesAndFolders.Count; i++)
1692-
{
1693-
if (FileExtensionHelpers.HasExtension(filesAndFolders[i].FileExtension, ".sln"))
1694-
{
1695-
SolutionFilePath = filesAndFolders[i].ItemPath;
1696-
return;
1697-
}
1698-
}
1699-
1700-
SolutionFilePath = null;
1692+
SolutionFilePath = filesAndFolders.ToList().AsParallel()
1693+
.Where(item => FileExtensionHelpers.HasExtension(item.FileExtension, ".sln"))
1694+
.FirstOrDefault()?.ItemPath;
17011695
}
17021696

17031697
private async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageItem item)

0 commit comments

Comments
 (0)