Skip to content

Fix selection not following items when changing sort order in folder compare - #3807

Merged
sdottaka merged 1 commit into
WinMerge:masterfrom
akarineren:fix-2625-selection-follows-sort
Dec 3, 2026
Merged

sdottaka merged 1 commit into
WinMerge:masterfrom
akarineren:fix-2625-selection-follows-sort

Conversation

@akarineren

Copy link
Copy Markdown
Contributor

Summary

Clicking a column header in the folder compare window re-sorts the rows, but the
selection, the focused row and the Shift-selection anchor stayed on the same row
positions, so a different set of files ended up selected.

Fixes #2625

Cause: The list is an owner-data list view, so the control tracks selection and
focus by row index, and SortColumnsAppropriately() only reorders m_listViewItems.

Fix: CDirView::OnColumnClick remembers the selected, focused and anchor items
before sorting and puts the state back on their new rows afterwards. Only the
column-click path is changed.

Testing

Based on master 07d2a91, x64 Release and x64 Debug builds, Windows 11.

Scenario Before After
Select bravo / echo / hotel, sort by Comparison Result delta / bravo / echo selected bravo / echo / hotel still selected
Tree mode, 3-way compare, ".." row, all selected, focus only selection or focus moves to other items unchanged
Sort by Filename while a compare is running selection moves to other items unchanged
Expand a folder above the selected item (#2359) OK OK

Time per header click with 20,000 rows: 28 ms → 29 ms with nothing selected,
29 ms → 54 ms with everything selected.

…compare

The folder compare list is an owner-data list view, so the control tracks
the selection, the focused row and the selection mark by row index.
Sorting only reorders m_listViewItems, which left a different set of items
selected after clicking a column header.

Remember the selected, focused and mark items in OnColumnClick before
sorting and put the state back on their new rows afterwards.

Fixes WinMerge#2625
@sdottaka
sdottaka merged commit 71ad499 into WinMerge:master Dec 3, 2026
@sdottaka

sdottaka commented Dec 3, 2026

Copy link
Copy Markdown
Member

Thank you!

@sdottaka sdottaka added this to the v2.16.61 milestone Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When changing ordering, selection doesn't follow selected items.

2 participants