Registry Mirror
Skip to content

Conversation

@christophwille

@christophwille christophwille commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #3993
Fixes #3994

Two regressions of the same shape from the Avalonia port: UI affordances that WPF wired up implicitly need explicit wiring in Avalonia, and both fell through the gap.

Fix 1: Main-menu keyboard shortcuts do nothing on Windows/Linux (#3993)

Symptom: Ctrl+O, Ctrl+S, and F5 show next to their File-menu items but pressing them has no effect. Alt+Left/Right and Ctrl+E keep working.

Root cause: The main menu is built as a NativeMenu, and NativeMenuItem.Gesture is display-only outside macOS. Decompiling Avalonia 12.1.1's NativeMenuBarPresenter (the managed fallback that renders the menu inline on Windows/Linux) confirms it: the presenter binds NativeMenuItem.Gesture to MenuItem.InputGesture, which only paints the shortcut text -- it never registers a key handler. Only macOS gets working shortcuts, because there the gestures become real NSMenu key equivalents. The Avalonia docs state this explicitly: "InputGesture only displays the text. You must also register the actual key binding separately for the shortcut to function." The shortcuts that kept working were exactly the ones hardcoded as KeyBindings in MainWindow.axaml; everything coming from [ExportMainMenuCommand(InputGestureText = ...)] metadata was display-only.

Fix: After the menu is built, MainMenu.RegisterGestureKeyBindings walks it recursively and adds a window-level KeyBinding for every item that has both a gesture and a command. Details:

  • It runs after TranslateGesturesForMacOS, so the bound gesture always matches the one the menu displays.
  • On macOS the system menu bar consumes its key equivalents before they reach the window, so the extra bindings stay dormant there -- no double dispatch.
  • Alt+Left/Right exist both in MainWindow.axaml and as menu gestures; that duplication is harmless because KeyboardDevice stops dispatching key bindings once one marks the event handled (verified in the decompiled Avalonia source), so only the first match executes.
  • MEF metadata (InputGestureText) stays the single source of truth -- no parallel shortcut list to maintain.

Test: Menu_Gestures_Are_Registered_As_Window_KeyBindings walks the built menu and asserts every displayed gesture has a matching window KeyBinding wired to the same command instance. Red before the fix (failed on Ctrl+O for File > Open), green after.

Fix 2: Documentation hover tooltip unreadable in dark mode (#3994)

Symptom: Hovering a symbol in the decompiled view with the dark theme active shows light-gray/blue text on a near-white box (see issue screenshot). Light mode looks fine.

Root cause: The hover popup is not an Avalonia ToolTip (those are already themed via the ToolTip style in App.axaml) -- it is a custom rich Popup whose content chrome was hardcoded in DocumentationRenderer.CreateView: background #FCFCFC, border #AAAAAA. The signature text inside it is coloured by the active highlighting theme, so in dark mode the light-on-dark syntax colours land on a light box. The hyperlink colour in rendered XML docs was hardcoded too (#0066CC), which would be equally unreadable on a dark popup.

Fix:

  • New theme-variant brushes in App.axaml: ILSpy.DocTooltipBackground / ILSpy.DocTooltipBorder / ILSpy.DocLinkForeground. The Light dictionary keeps the exact previous values (#FCFCFC / #AAAAAA / #0066CC), so light mode is pixel-identical. The Dark dictionary uses #252526 / #3F3F46 (matching the themed tooltip surface, slightly lighter than the #1E1E1E editor canvas so the popup reads as raised) and a brightened link blue #6FA8DC.
  • These are deliberately separate from the existing ILSpy.Tooltip* brushes: the plain tooltip uses the classic yellow #FFFFE1 fill, which is wrong for a popup showing syntax-coloured code.
  • DocumentationRenderer.CreateView now binds the popup chrome via GetResourceObservable (the same pattern DecompilerTextEditor uses for the editor background), and the link colour moved into a TextBlock.doc-link style -- both follow live theme switches.

Tests: DocumentationRendererThemeTests.Popup_Chrome_Follows_The_Active_Theme_Variant pins the dark chrome under ThemeVariant.Dark and pins light mode to the unchanged near-white values; the existing SeeCref link test gained an assertion that doc links use the themed foreground. Both red before the fix, green after.

Full ILSpy.Tests suite green on Windows with both fixes in place: 1176 tests, 0 failed, 4 skipped.

🤖 Generated with Claude Code

@christophwille christophwille left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Code review

Read every hunk and verified the claims by decompiling Avalonia 12.1.1 (KeyBinding, KeyboardDevice, NativeMenuItem, Popup, Avalonia.Native's menu-item proxy), plus empirical runs on macOS (arm64).

Both fixes are correct, and both work on macOS. Full ILSpy.Tests on this branch: 1173 passed, 0 failed, 3 skipped.

Probes for what the PR's own tests do not cover:

  • Rendering the doc popup inside a real Popup (the new test only uses a Window): dark -> border #252526, chrome #3f3f46, body #dedede, link #6fa8dc; light -> #fcfcfc / black / #0066cc. Foreground inheritance does cross the PopupRoot boundary, so the body text is readable in both variants -- the fix is complete, not just the chrome.
  • Window-level KeyBinding dispatch while a TextBox has focus: fires. KeyboardDevice.ProcessRawEvent walks focused-element -> visual ancestors and runs KeyBindings before raising KeyDown, so the fix is not shadowed by focused controls.

macOS specifics

  • __MicroComIAvnMenuItemProxy.UpdateGesture -> SetGesture(key, modifiers) confirms NativeMenuItem.Gesture becomes a real NSMenu key equivalent, so the menu consumes it and the extra window bindings are inert there. Even in the inverted case (Avalonia's RawKeyEvent returns a handled-bool to native, so AvnView could run managed input first), exactly one path executes: KeyBinding.TryHandle gates on Command.CanExecute, and NativeMenuItem.IsEnabled is itself SetCurrentValue(..., Command?.CanExecute(...)), so the two gates always agree. No double dispatch either way.
  • RegisterGestureKeyBindings is correctly placed after TranslateGesturesForMacOS, so the registered gesture matches the displayed one (Cmd on macOS).
  • The Alt+Left/Alt+Right duplication with MainWindow.axaml is harmless: KeyBinding.TryHandle only sets Handled when CanExecute is true and KeyboardDevice stops the loop on Handled; both route to the same inner NavigateBackCommand.

Nothing in the diff is a correctness bug. Three low-severity items inline.

Note outside the diff (macOS-relevant)

ILSpy/Views/MainWindow.axaml:25-32 hardcodes Ctrl+E, Ctrl+W, Ctrl+Shift+F as KeyBindings. Unlike the menu gestures these do not go through TranslateGesturesForMacOS, so on macOS they still require Ctrl rather than Cmd. Pre-existing, not introduced here, but it is the remaining half of the same "shortcuts on macOS" story and the new comment block in MainMenu.axaml.cs reasons about exactly these bindings -- worth a follow-up issue.

Comment thread ILSpy/Views/MainMenu.axaml.cs Resolved
Comment thread ILSpy.Tests/MainWindow/MainMenuTests.cs Resolved
NativeMenuItem.Gesture is display-only when NativeMenuBar renders the
menu inline on Windows/Linux: the managed fallback binds it to
MenuItem.InputGesture, which never handles input. Only macOS's system
menu bar actually executes its key equivalents, so Ctrl+O, Ctrl+S and
F5 showed in the menu but did nothing. The Avalonia docs call this out
explicitly: InputGesture only displays the text and must be paired with
a KeyBinding for the shortcut to function.

Assisted-by: Claude:claude-fable-5:Claude Code
The rich hover popup hardcoded a near-white background and border while
its signature text is coloured by the active highlighting theme, so in
dark mode light-on-dark syntax colours landed on a light box and were
unreadable. The chrome and the doc-link colour now route through
theme-variant brushes; light mode keeps the established near-white look.

Assisted-by: Claude:claude-fable-5:Claude Code
@christophwille
christophwille force-pushed the fix-3993-menu-shortcuts branch from 74939a6 to 0d244f4 Compare August 14, 2026 12:32
@christophwille

Copy link
Copy Markdown
Member Author

All three inline items are addressed and squashed into their respective commits (branch force-pushed, now 36b870d3e / 0d244f4d7):

  • CommandParameter snapshot -- the shortcut's KeyBinding now binds CommandParameterProperty to the item's property via GetObservable, so IProvideParameterBinding commands resolve their parameter at shortcut time the same way a menu click does.
  • File header -- the new test file now credits Christoph Wille.
  • Test brittleness -- the gesture collector mirrors the production condition (Gesture != null && Command != null), so display-only gestures can't fail the assertion.

MainMenuTests + DocumentationRendererThemeTests re-run green after the changes.

On the out-of-diff note: agreed that the hardcoded Ctrl+E / Ctrl+W / Ctrl+Shift+F bindings in MainWindow.axaml are the remaining half of the macOS shortcut story, since they bypass TranslateGesturesForMacOS. Left out of this PR to keep it scoped to the two linked issues -- worth its own follow-up issue.

🤖 Generated with Claude Code

@christophwille
christophwille merged commit deb1da3 into master Aug 16, 2026
15 checks passed
@christophwille
christophwille deleted the fix-3993-menu-shortcuts branch August 16, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ILSpy version 11.0.0.9375: ToolTip rendering not readable. Some hotkeys not working in 11.0.0.9375

2 participants