-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
make selection model properly handle incc move events without droppin… #19886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where moving a selected item in an INCC (INotifyCollectionChanged) collection would incorrectly clear the selection. The fix properly handles move events by transforming them into dedicated move operations instead of treating them as separate remove and add operations.
Key Changes:
- Added logic to detect and handle move operations within the selection model
- Introduced
OnSelectionMovedvirtual method to manage selection state during moves - Enhanced
CollectionChangeStateto track deselected ranges for move detection
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| SelectionNodeBase.cs | Added move detection logic and OnSelectionMoved method to handle selection preservation during move operations |
| SelectionModel.cs | Implemented OnSelectionMoved override to update selected and anchor indexes during moves |
| SelectionModelTests_Single.cs | Updated existing test and added new test to verify selection is preserved during move operations |
| SelectionModelTests_Multiple.cs | Updated existing test and added new test to verify multiple selection is preserved during move operations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| { | ||
| var relativeBegin = range.Begin - e.OldStartingIndex; | ||
| var begin = insertIndex + relativeBegin; | ||
| var end = begin + (range.End - range.Begin); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The calculation for end could be simplified for clarity. Instead of begin + (range.End - range.Begin), consider using insertIndex + (range.End - e.OldStartingIndex) to make the relationship to the original range more explicit.
| var end = begin + (range.End - range.Begin); | |
| var end = insertIndex + (range.End - e.OldStartingIndex); |
| IReadOnlyList<IndexRange> newSelectedRanges, | ||
| IReadOnlyList<T> movedItems) | ||
| { | ||
| _ = movedItems; |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The discard _ = movedItems; is unnecessary since unused parameters in method overrides don't generate warnings. Consider removing this line for cleaner code.
| _ = movedItems; |
|
You can test this PR using the following package version. |
Currently if your underlying INCC collection emits move events for the selected item, the selection model will clear the selection. Because it turns the move into a Remove and Add.
This PR properly handles the move events, so a move operation occurs on the selection model too.
The selection is now maintained.
before:
https://github.com/user-attachments/assets/b8f8cb64-510d-4ecc-8ab5-c555d72b5cc2
after:
https://github.com/user-attachments/assets/ebde2759-3e82-4882-be64-f904b2911558