Skip to content

Bug: Changing sort option clears selected items #14252

Open

Description

@koppor

Description

I have a folder with hundreds of files. Loading hasn't finished in Files. I select a file. It is previewed. After a few seconds, it changes to another picture. Then, it changes again.

Maybe, this refs #6870

Steps To Reproduce

  1. Select an item
  2. Change sort direction
  3. Notice the selected item is no longer selected

Requirements

  • Keep selection

Files Version

3.7.11

Windows Version

10.0.19045.3803

Log File

debug.log

Activity

  1. Josh65-2201 commented on Dec 17, 2023

    @Josh65-2201
    Member

    Thanks for the report, Do you mean the image that is selected changes or the preview reload the same image?

  2. added
    needs - additional info
    on Dec 17, 2023
  3. koppor commented on Dec 19, 2023

    @koppor
    Author

    Do you mean the image that is selected changes

    No. The selected images stays the same.

    or the preview reload the same image?

    The preview reloads every few seconds with another image.

  4. changed the title [-]Image preview should not update when nothing changes[/-] [+]Bug: Details should not keep changing as items are still loading[/+] on Jan 14, 2024
  5. yair100 commented on Jan 14, 2024

    @yair100
    Member

    How many items are in the folder?

  6. koppor commented on Jan 15, 2024

    @koppor
    Author

    Maybe 1500 on a Samba file share. Could be 2500.

  7. yair100 commented on Jan 15, 2024

    @yair100
    Member

    Is this only an issue on the Samba share or can you repro it on a local drive as well?

  8. yair100 commented on Feb 22, 2024

    @yair100
    Member
  9. koppor commented on Mar 5, 2024

    @koppor
    Author

    As of today, its even worse. I click a file. preview is there. Then it is deselected and I have endless loading:

    (image removed)

    The app is totally unresponsive.

    Test setting: Folder with 88.000 images.

    In comparison, Windows Explorer loads every fast:

    (image removed)

  10. yair100 commented on Mar 5, 2024

    @yair100
    Member

    Is this only an issue on the Samba share or can you repro it on a local drive as well?

  11. koppor commented on Mar 5, 2024

    @koppor
    Author

    C:\temp\full with 80.000 files (shown above) is in a locally attached M2 disk. NTFS formatted. No Samba share.

    One can see the local path in the Files Screenshot.

    I promise, I did not create a symlink and that it is really a local directory.

  12. koppor commented on Mar 6, 2024

    @koppor
    Author

    Update:

    Powershell script to collect all images into c:\temp\full

    $sourcePath = "B:\" # Update this path
    $destinationPath = "C:\temp\full"
    
    # Define the minimum free space required
    $minFreeSpace = 1000MB
    
    # Search for .jpg files and process each file immediately when found
    Get-ChildItem -Path $sourcePath -Recurse -Filter "*.jpg" | ForEach-Object {
        # Calculate the current available space on the destination drive
        $driveInfo = Get-PSDrive -Name (Get-Item $destinationPath).PSDrive.Name
        $availableSpace = $driveInfo.Free
    
        # Check if the available space is below the threshold
        if ($availableSpace -le $minFreeSpace + $_.Length) {
            Write-Host "Available space is below threshold. Stopping the copy process."
            break
        }
    
        $destinationFile = Join-Path -Path $destinationPath -ChildPath $_.Name
    
        # Check if the file already exists at the destination
        if (Test-Path -Path $destinationFile) {
            Write-Host "File already exists, skipping: $destinationFile"
            return # Skip this file and move to the next one
        }
    
        # Copy the file to the destination
        Copy-Item -Path $_.FullName -Destination $destinationFile
    
        Write-Host "Copied: $($_.FullName) to $destinationPath"
    }
    
    Write-Host "Copy operation completed."
  13. yair100 commented on Oct 1, 2024

    @yair100
    Member

    Is this still an issue in the preview version? https://files.community/download/preview

  14. koppor commented on Oct 13, 2024

    @koppor
    Author

    Now it is very different. While loading the directory contents, it jumps away from the selected image. Meaning: I click on an image, then the selection moves away...

    Should I open a new issue for that or should we discuss on this issue?

  15. yair100 commented on Oct 13, 2024

    @yair100
    Member

    I think the actual issue is that sorting items clears the selection (items are sorted after they are finished loading). You can confirm by selecting an item and changing the sort direction.

  16. changed the title [-]Bug: Details should not keep changing as items are still loading[/-] [+]Bug: Changing sort option clears selected items[/+] on Oct 13, 2024
  17. removed
    needs - additional info
    on Oct 13, 2024
  18. moved this from 🆕 New to 🔖 Ready to build in Files task boardon Oct 13, 2024
  19. koppor commented on Oct 13, 2024

    @koppor
    Author

    I think the actual issue is that sorting items clears the selection (items are sorted after they are finished loading).

    The blue selection arrow moved down while loading - no selection clearing was made.

  20. yair100 commented on Oct 13, 2024

    @yair100
    Member

    Now it is very different. While loading the directory contents, it jumps away from the selected image. Meaning: I click on an image, then the selection moves away...

    Perhaps I was a bit hasty in editing the issue details 🙂

    Can you clarify where the selection moves to?

  21. koppor commented on Oct 13, 2024

    @koppor
    Author

    Now it is very different. While loading the directory contents, it jumps away from the selected image. Meaning: I click on an image, then the selection moves away...
    Can you clarify where the selection moves to?

    It moves down... I think, the tool gets the files in some random order, but displayes it in alphabetical order.

  22. yair100 commented on Oct 13, 2024

    @yair100
    Member

    To the next file? Are you able to upload a screen recording (you can upload directly to GitHub)?

  23. koppor commented on Oct 14, 2024

    @koppor
    Author

    I need to create a script to create random images (because I don't want to share my private images here on GitHub using a video).

    After the second run, it seemed to keep the positoin. However, after switching back to the application after 2 hours, it just hangs:

    Image

    38538 File(s) 141.514.917.854 bytes
    
  24. h-sane commented on Nov 30, 2026

    @h-sane

    Hi, I'd like to work on this one if it's still open. From reading the code, it looks like re-sorting rebuilds the list in one reset, which drops the selection. I'll confirm on a current build and restore the selection after the sort, and check the group-by options too since they take the same path.

  25. yair100 commented on Nov 30, 2026

    @yair100
    Member

    @h-sane due to an increase in AI generated PRs, we're currently only accepting PRs from previous contributors.

  26. h-sane commented on Nov 30, 2026

    @h-sane

    Got it, thanks for letting me know. I'd already traced it, so here's what I found in case it saves whoever picks this up some time.

    In ShellViewModel.cs (around line 500), all 4 sort handlers end in ApplyFilesAndFoldersChangesAsync. That clears the list and re-adds every item in one bulk operation (line 1157), so the ListView gets a single Reset. The Reset is what drops the selection.

    The fix looks small. The ListedItem objects stay the same references after OrderFileList, so I'd copy SelectedItems in BaseShellPage.cs before the update and call ItemManipulationModel.SetSelectedItems afterwards. Grouping probably has the same bug, since GroupPreferenceUpdatedAsync in BaseLayoutPage.cs also ends in a bulk reset.

    One caveat: I haven't run this on a build yet. Treat it as a lead. PR #2883 tried the same thing back in 2021 and was closed when its author went quiet, so it might be worth a look too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions