Conversation
christophwille
left a comment
There was a problem hiding this comment.
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 aWindow): dark -> border#252526, chrome#3f3f46, body#dedede, link#6fa8dc; light ->#fcfcfc/ black /#0066cc. Foreground inheritance does cross thePopupRootboundary, so the body text is readable in both variants -- the fix is complete, not just the chrome. - Window-level
KeyBindingdispatch while aTextBoxhas focus: fires.KeyboardDevice.ProcessRawEventwalks focused-element -> visual ancestors and runsKeyBindingsbefore raisingKeyDown, so the fix is not shadowed by focused controls.
macOS specifics
__MicroComIAvnMenuItemProxy.UpdateGesture->SetGesture(key, modifiers)confirmsNativeMenuItem.Gesturebecomes a real NSMenu key equivalent, so the menu consumes it and the extra window bindings are inert there. Even in the inverted case (Avalonia'sRawKeyEventreturns a handled-bool to native, soAvnViewcould run managed input first), exactly one path executes:KeyBinding.TryHandlegates onCommand.CanExecute, andNativeMenuItem.IsEnabledis itselfSetCurrentValue(..., Command?.CanExecute(...)), so the two gates always agree. No double dispatch either way.RegisterGestureKeyBindingsis correctly placed afterTranslateGesturesForMacOS, so the registered gesture matches the displayed one (Cmd on macOS).- The Alt+Left/Alt+Right duplication with
MainWindow.axamlis harmless:KeyBinding.TryHandleonly setsHandledwhenCanExecuteis true andKeyboardDevicestops the loop onHandled; both route to the same innerNavigateBackCommand.
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.
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
74939a6 to
0d244f4
Compare
|
All three inline items are addressed and squashed into their respective commits (branch force-pushed, now
On the out-of-diff note: agreed that the hardcoded 🤖 Generated with Claude Code |
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, andNativeMenuItem.Gestureis display-only outside macOS. Decompiling Avalonia 12.1.1'sNativeMenuBarPresenter(the managed fallback that renders the menu inline on Windows/Linux) confirms it: the presenter bindsNativeMenuItem.GesturetoMenuItem.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: "InputGestureonly 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 asKeyBindingsinMainWindow.axaml; everything coming from[ExportMainMenuCommand(InputGestureText = ...)]metadata was display-only.Fix: After the menu is built,
MainMenu.RegisterGestureKeyBindingswalks it recursively and adds a window-levelKeyBindingfor every item that has both a gesture and a command. Details:TranslateGesturesForMacOS, so the bound gesture always matches the one the menu displays.MainWindow.axamland as menu gestures; that duplication is harmless becauseKeyboardDevicestops dispatching key bindings once one marks the event handled (verified in the decompiled Avalonia source), so only the first match executes.InputGestureText) stays the single source of truth -- no parallel shortcut list to maintain.Test:
Menu_Gestures_Are_Registered_As_Window_KeyBindingswalks the built menu and asserts every displayed gesture has a matching windowKeyBindingwired 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 theToolTipstyle inApp.axaml) -- it is a custom richPopupwhose content chrome was hardcoded inDocumentationRenderer.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:
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#1E1E1Eeditor canvas so the popup reads as raised) and a brightened link blue#6FA8DC.ILSpy.Tooltip*brushes: the plain tooltip uses the classic yellow#FFFFE1fill, which is wrong for a popup showing syntax-coloured code.DocumentationRenderer.CreateViewnow binds the popup chrome viaGetResourceObservable(the same patternDecompilerTextEditoruses for the editor background), and the link colour moved into aTextBlock.doc-linkstyle -- both follow live theme switches.Tests:
DocumentationRendererThemeTests.Popup_Chrome_Follows_The_Active_Theme_Variantpins the dark chrome underThemeVariant.Darkand pins light mode to the unchanged near-white values; the existingSeeCreflink test gained an assertion that doc links use the themed foreground. Both red before the fix, green after.Full
ILSpy.Testssuite green on Windows with both fixes in place: 1176 tests, 0 failed, 4 skipped.🤖 Generated with Claude Code