Skip to content

Commit 633bae0

Browse files
authored
Revert "Fix: Fixed issue where the app could crash when adding items from external apps" (#14624)
1 parent e454ac5 commit 633bae0

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,51 @@ void ClearDisplay()
699699
// run safely without needs of dispatching to UI thread
700700
void ApplyChanges()
701701
{
702-
if (addFilesCTS.IsCancellationRequested)
703-
return;
702+
var startIndex = -1;
703+
var tempList = new List<ListedItem>();
704704

705-
FilesAndFolders.Clear();
706-
FilesAndFolders.AddRange(filesAndFoldersLocal);
705+
void ApplyBulkInsertEntries()
706+
{
707+
if (startIndex != -1)
708+
{
709+
FilesAndFolders.ReplaceRange(startIndex, tempList);
710+
startIndex = -1;
711+
tempList.Clear();
712+
}
713+
}
714+
715+
for (var i = 0; i < filesAndFoldersLocal.Count; i++)
716+
{
717+
if (addFilesCTS.IsCancellationRequested)
718+
return;
719+
720+
if (i < FilesAndFolders.Count)
721+
{
722+
if (FilesAndFolders[i] != filesAndFoldersLocal[i])
723+
{
724+
if (startIndex == -1)
725+
startIndex = i;
726+
727+
tempList.Add(filesAndFoldersLocal[i]);
728+
}
729+
else
730+
{
731+
ApplyBulkInsertEntries();
732+
}
733+
}
734+
else
735+
{
736+
ApplyBulkInsertEntries();
737+
FilesAndFolders.InsertRange(i, filesAndFoldersLocal.Skip(i));
738+
739+
break;
740+
}
741+
}
742+
743+
ApplyBulkInsertEntries();
744+
745+
if (FilesAndFolders.Count > filesAndFoldersLocal.Count)
746+
FilesAndFolders.RemoveRange(filesAndFoldersLocal.Count, FilesAndFolders.Count - filesAndFoldersLocal.Count);
707747

708748
if (folderSettings.DirectoryGroupOption != GroupOption.None)
709749
OrderGroups();

0 commit comments

Comments
 (0)