Repository navigation
Report deselected items and batch SelectAll in TreeView - #22172
Merged
Merged
Conversation
Selecting a different item clears and repopulates SelectedItems. The clear raises a Reset, which carries no OldItems, so the deselection was dropped and only the addition was reported. Track the previous selection so the reset can work out what was deselected, and raise the clear and the add as one event. SelectAll added items one at a time, raising an event per item. Batch it the same way.
|
You can test this PR using the following package version. |
grokys
reviewed
Sep 11, 2026
grokys
requested changes
Sep 11, 2026
grokys
left a comment
Member
There was a problem hiding this comment.
See previous comment that the LLM posted without requesting changes, sigh.
Keep a single snapshot of the last reported selection and diff against it, instead of tracking the snapshot and the pending changes separately. A reset that keeps some items no longer reports them as added. Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
|
You can test this PR using the following package version. |
NuGet packagesThe packages for this pull request have been published (workflow run):
|
grokys
force-pushed
the
fix-treeview-selection-removed
branch
from
October 7, 2026 07:39
f29cad2 to
205399e
Compare
No other fields have comments, pretty much in the whole codebase. This isn't an exception.
grokys
approved these changes
Oct 7, 2026
grokys
left a comment
Member
There was a problem hiding this comment.
LGTM, much simpler! I removed a comment on a field (almost no other fields in Avalonia merit a comment, and I don't think this one was really an exception)
grokys
enabled auto-merge
October 7, 2026 07:42
MrJul
pushed a commit
that referenced
this pull request
Oct 9, 2026
* Report deselected items and batch SelectAll in TreeView Selecting a different item clears and repopulates SelectedItems. The clear raises a Reset, which carries no OldItems, so the deselection was dropped and only the addition was reported. Track the previous selection so the reset can work out what was deselected, and raise the clear and the add as one event. SelectAll added items one at a time, raising an event per item. Batch it the same way. * Simplify TreeView selection tracking Keep a single snapshot of the last reported selection and diff against it, instead of tracking the snapshot and the pending changes separately. A reset that keeps some items no longer reports them as added. Co-authored-by: Steven Kirk <grokys@users.noreply.github.com> * Simplify comments * Remove comment. No other fields have comments, pretty much in the whole codebase. This isn't an exception. --------- Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Addresses two of the three things reported in #22116: deselected items aren't reported, and
SelectAllraises one event per item.The third point in that issue,
ISelectionModelsupport forTreeView, is a public API addition rather than a bug, so I've left it alone and haven't usedFixes.What is the current behavior?
Selecting one item and then another logs:
The first item is deselected but never reported. Ctrl+A on four items raises four separate events.
What is the updated/expected behavior with this PR?
Ctrl+A raises one event containing all the items. This matches what
ListBoxalready does.How was the solution implemented (if it's not obvious)?
SelectSingleItemclearsSelectedItemsand then adds to it.AvaloniaList.Clearraises aReset, and a reset carries noOldItems, so there was nothing to report the deselection from. The control now keeps the previous selection so the reset case can work out what went away.Doing only that would turn one event into two, so the clear and the add are now batched and raised as a single event.
SelectAlluses the same batching.I used a separate flag for the batching rather than reusing
_syncingSelectedItems, since that one also gates someSelectedItembookkeeping that shouldn't change. Both call sites use try/finally so a failure part way through can't leave the control swallowing events.Checklist
Two tests, both of which fail on main.
Breaking changes
Handlers that assumed
RemovedItemswas always empty, or that counted one event per item fromSelectAll, will see different values. The selection itself is unchanged.Related issues
Part of #22116