Skip to content

Commit

Permalink
Fix: Fixed an issue where the file area would sometimes lose focus wh…
Browse files Browse the repository at this point in the history
…en opening a folder (#13130)
  • Loading branch information
hishitetsu authored Aug 6, 2023
1 parent 65b2519 commit 2dfdd3f
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ void ClearDisplay()

return;
}
var filesAndFoldersLocal = filesAndFolders.ToList();

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

for (var i = 0; i < filesAndFolders.Count; i++)
for (var i = 0; i < filesAndFoldersLocal.Count; i++)
{
if (addFilesCTS.IsCancellationRequested)
return;

if (i < FilesAndFolders.Count)
{
if (FilesAndFolders[i] != filesAndFolders[i])
if (FilesAndFolders[i] != filesAndFoldersLocal[i])
{
if (startIndex == -1)
startIndex = i;

tempList.Add(filesAndFolders[i]);
tempList.Add(filesAndFoldersLocal[i]);
}
else
{
Expand All @@ -665,16 +666,16 @@ void ApplyBulkInsertEntries()
else
{
ApplyBulkInsertEntries();
FilesAndFolders.InsertRange(i, filesAndFolders.ToList().Skip(i));
FilesAndFolders.InsertRange(i, filesAndFoldersLocal.Skip(i));

break;
}
}

ApplyBulkInsertEntries();

if (FilesAndFolders.Count > filesAndFolders.Count)
FilesAndFolders.RemoveRange(filesAndFolders.Count, FilesAndFolders.Count - filesAndFolders.Count);
if (FilesAndFolders.Count > filesAndFoldersLocal.Count)
FilesAndFolders.RemoveRange(filesAndFoldersLocal.Count, FilesAndFolders.Count - filesAndFoldersLocal.Count);

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

filesAndFolders.AddRange(fileList);

await dispatcherQueue.EnqueueOrInvokeAsync(CheckForSolutionFile, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
await OrderFilesAndFoldersAsync();
await ApplyFilesAndFoldersChangesAsync();
await dispatcherQueue.EnqueueOrInvokeAsync(CheckForSolutionFile, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
});

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

private void CheckForSolutionFile()
{
for (int i = 0; i < filesAndFolders.Count; i++)
{
if (FileExtensionHelpers.HasExtension(filesAndFolders[i].FileExtension, ".sln"))
{
SolutionFilePath = filesAndFolders[i].ItemPath;
return;
}
}

SolutionFilePath = null;
SolutionFilePath = filesAndFolders.ToList().AsParallel()
.Where(item => FileExtensionHelpers.HasExtension(item.FileExtension, ".sln"))
.FirstOrDefault()?.ItemPath;
}

private async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageItem item)
Expand Down

0 comments on commit 2dfdd3f

Please sign in to comment.