Skip to content

Dropdowns and single-selection lists can't be cleared by Ctrl+Space or Ctrl+click (#107) - #110

Merged
KnifeLemon merged 1 commit into
mainfrom
fix/dropdown-ctrl-space
Oct 18, 2026
Merged

KnifeLemon merged 1 commit into
mainfrom
fix/dropdown-ctrl-space

Conversation

@KnifeLemon

Copy link
Copy Markdown
Owner

Summary

Fixes #107. Pressing Ctrl+Space twice on a focused dropdown threw a NullReferenceException, shown as red text under the combo on the Shortcuts page and elsewhere.

Cause (Avalonia 12.1.3):

  1. The first Ctrl+Space opens the dropdown and focuses the selected item.
  2. The second one goes through SelectingItemsControl.UpdateSelectionFromEvent, which treats Ctrl (Cmd on macOS) as "toggle" and sets SelectedIndex = -1 in single-selection mode.
  3. Ctrl+Enter or a Ctrl+click on the selected item does the same.
  4. The null then reached non-nullable Choice<T> properties.

The sidebar nav list had the same problem: Ctrl+clicking the current page made CreatePage(null) fail.

Fix

  • SingleSelectionGuard blocks toggle input on an already-selected item in ComboBoxes and single-selection ListBoxes. It covers the KeyDown, PointerPressed and PointerReleased tunnel handlers and uses Avalonia's own trigger and modifier checks. Arrows, Enter/Space to open, Ctrl+clicking another item and multi-select lists behave as before.
  • Defensive: Choices.Restore makes every Choice<T> and nav property keep its previous value when null arrives. The guard re-reads the binding so the control shows that value again.
  • Applied in:
    • TriggerGestureViewModel
    • PresetEditorViewModel (all combos)
    • GeneralPageViewModel
    • ThemePageViewModel
    • WatchRuleViewModel
    • RenameStepViewModel
    • MainWindowViewModel

Test plan

  • 6 new SelectionGuardTests:

    • real Triggers-page combo with Ctrl+Space Γ—4
    • Ctrl+click on the selected item
    • forced null
    • nav Ctrl+click
    • multi-select lists still toggle
    • null handling on every VM property

    Without the fix, 5 of them fail.

  • App 271 and Core 200 tests pass. dotnet format is clean.

πŸ€– Generated with Claude Code

Avalonia toggles the selected item of a ComboBox or ListBox off when it is
picked again with the command modifier (Ctrl+Space, Ctrl+Enter, Ctrl+click;
Cmd on macOS). A combo box was left empty and pushed null into settings that
always hold a value, which threw NullReferenceException in the view models
(e.g. TriggerGestureViewModel) and showed it under the combo box.

- SingleSelectionGuard (registered in App.Initialize) swallows that toggle on
  the selected item of combo boxes and single-selection list boxes; an open
  drop-down closes as after any pick. Multi-selection lists keep the toggle.
- Choices.Restore: every Choice<T> property (Triggers, Presets editor,
  General, Theme, Watch folders, rename rules) and the navigation selection
  ignore null and keep their previous value; the control then reads the bound
  value again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KnifeLemon
KnifeLemon merged commit 60494af into main Oct 18, 2026
5 checks passed
@KnifeLemon
KnifeLemon deleted the fix/dropdown-ctrl-space branch October 19, 2026 12:55
@KnifeLemon KnifeLemon self-assigned this Oct 20, 2026
@KnifeLemon KnifeLemon added the bug Something isn't working label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dropdown List throwing exceptions

1 participant