Skip to content

Keep the package list's scroll position when an operation completes - #5512

Merged
Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/keep-scroll-on-operation-complete
Oct 13, 2026
Merged

Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/keep-scroll-on-operation-complete

Conversation

@GabrielDuf

@GabrielDuf Gabriel Dufresne (GabrielDuf) commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Cause

When an install/update/uninstall finishes, the operation adds/removes the package through the loader's procedural Remove/AddForeign path. The page answered by calling FilterPackages, which did FilteredPackages.Clear() and re-added every row. Clear() raises a Reset, and the DataGrid returns to the top on a Reset, so every completed operation scrolled the list view back to row 0 even though one row changed.

Headless Avalonia repro (same DataGrid version, 500 rows, scrolled to row 289):

Change Offset before → after First visible row
Clear() + re-add (old) 9264 → 0 pkg289 → pkg000
single Remove 9264 → 9264 pkg289
single Insert 9264 → 9264 pkg289
insert/remove above the viewport adjusts by the row height pkg289 (anchored)

Fix

  • Procedural loader changes now apply only the delta: removed wrappers are taken out by reference, and new wrappers that pass the current search/source filter are inserted at their sorted position (after equal keys, where a stable full sort would put them) — ObservablePackageCollection.ApplyChanges.
  • Full reloads, searches, sorts and filter changes still rebuild the list and go to the top as before, so a search still shows the first matches and doesn't become thousands of individual Remove notifications.
  • ApplyToList now sorts through the same comparer used by the insert, so they can't disagree. Checked against the previous OrderBy/OrderByDescending/ThenBy chain over 20,000 random orderings (both directions, download-size sort, ties): identical.
  • Removed the unused fromQuery parameter of FilterPackages; split out BuildPackageFilter / UpdateFilteredState so both paths share them.
  • New ObservablePackageCollectionTests (5 tests, incl. a 500-case randomized comparison with a full stable sort; a deliberate tie-break mutation fails 2 of them).

Reviewer notes

  • Trade-off: a row whose sort key changes in place (e.g. its version under a Version sort) keeps its position until the next full refilter, rather than the whole list being rebuilt.
  • Grid/Icons views never had this jump (their ScrollViewer kept the offset through Clear()); the fix is for the default List view.
  • Not yet tested in the running app: scroll down in Updates, update one package, and the list should stay put.

Closes #5505

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The incremental update path is consistent with existing filtering and sorting behavior and is adequately covered by focused tests.

0 open findings

What changed in this PR

Preserves package-list scroll position by incrementally updating filtered rows when operations complete.

Changes:

  • Adds reference-based removals and stable sorted insertions.
  • Shares filtering, state updates, and sorting logic.
  • Adds coverage for incremental collection behavior.
File Description
src/​UniGetUI.Tests/​ObservablePackageCollectionTests.cs Tests removals, insertion order, notifications, and stable sorting.
src/​UniGetUI.Avalonia/​ViewModels/​SoftwarePages/​PackagesPageViewModel.cs Applies procedural package deltas without resetting the collection.
src/​UniGetUI.Avalonia/​Models/​PackageCollections.cs Implements incremental updates and unified comparison logic.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@randy-but-a-ro randy-but-a-ro Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Pull request was approved automatically: the AI review is complete and all its review threads are resolved. 🎉

Integration Details
{
	"deliveryId": "82247bb0-c731-11f1-81db-30b6c68fe9b9",
	"headSha": "85df2964bc91f4ced83dc3509b04bc9cb97b2462",
	"reviewer": "copilot-pull-request-reviewer[bot]"
}

@GabrielDuf
Gabriel Dufresne (GabrielDuf) merged commit c6fa04c into main Oct 13, 2026
9 of 10 checks passed
@GabrielDuf
Gabriel Dufresne (GabrielDuf) deleted the fix/keep-scroll-on-operation-complete branch October 13, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] UI keeps scrolling back to the top once an operation completes

2 participants