Skip to content

CmdPal: Fix missing primary context command for late-bound items#46131

Merged
michaeljolley merged 1 commit intomainfrom
dev/jpolasek/b/46129-cmdpal-fix-default-command-when-init-as-empty
Mar 24, 2026
Merged

CmdPal: Fix missing primary context command for late-bound items#46131
michaeljolley merged 1 commit intomainfrom
dev/jpolasek/b/46129-cmdpal-fix-default-command-when-init-as-empty

Conversation

@jiripolasek
Copy link
Copy Markdown
Collaborator

This PR does fix a bug where an item that starts with a null or empty primary command never adds that primary action to the context menu after the extension later provides a real command.

  • Creates the default primary context-menu item lazily when Command or Command.Name becomes available after SlowInitializeProperties()
  • Refreshes AllCommands, SecondaryCommand, and HasMoreCommands notifications for late command materialization and Show Details updates.
  • Adds unit tests to cover the fixed issue.

Summary of the Pull Request

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

…d commands

- Creates the default primary context-menu item lazily when Command or Command.Name becomes available after SlowInitializeProperties().
- Refreshes AllCommands, SecondaryCommand, and HasMoreCommands notifications for late command materialization and Show Details updates.
- Keeps the snapshot-based context menu flow intact while ensuring the primary command participates in the context menu.
- Adds a unit test for the issue.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a CmdPal context-menu bug where a CommandItem that initially has a null/empty primary command never gets a synthetic “primary” context-menu entry when the extension later supplies a real command.

Changes:

  • Adds a lazy path to create the synthetic primary CommandContextItemViewModel when Command/Command.Name becomes available after SlowInitializeProperties().
  • Ensures SecondaryCommand/SecondaryCommandName/HasMoreCommands notifications are raised when “MoreCommands” is modified internally (e.g., Show Details injection) and after slow init.
  • Adds unit tests covering late primary command materialization and subtitle propagation behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandItemViewModel.cs Lazily creates the synthetic primary context item on late command/name updates and refreshes related property notifications during slow init.
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs Raises SecondaryCommand* and HasMoreCommands notifications when Show Details is added/updated in the context menu.
src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/CommandItemViewModelTests.cs Adds regression tests for late primary command creation and subtitle propagation into the synthetic primary context item.

Copy link
Copy Markdown
Contributor

@michaeljolley michaeljolley left a comment

Choose a reason for hiding this comment

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

Image

@michaeljolley michaeljolley merged commit 3f35b11 into main Mar 24, 2026
19 checks passed
@michaeljolley michaeljolley deleted the dev/jpolasek/b/46129-cmdpal-fix-default-command-when-init-as-empty branch March 24, 2026 22:24
zateutsch added a commit that referenced this pull request Mar 25, 2026
Cherry-picked commits:
- Make KBM Editor pinnable (#46482)
- CmdPal: Fix missing primary context command for late-bound items (#46131)
- CmdPal: Ensure DockWindow property cleans up after itself (#46303)
- CmdPal: Hotfix commonCallbacks array initial count to prevent negative number (#46215)
- CmdPal: Fix missing app context menu actions on the main page (#46293)
- CmdPal: Fix dock popup XamlRoot handling on DockControl (#46305)
- CmdPal: Reduce DockWindow backdrop switching and visual artifacts (#46309)
- Always On Top: The opacity should be able to configure the hotkey individually (#46410)
- [OOBE] Ensure the Settings button on the SCOOBE page opens Home, not a blank page (#46203)
- CmdPal: Fix scroller scrolling and down glyph (#46447)
- [Settings] Decouple Settings.UI.Library from PowerDisplay.Lib to fix (#46325)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.98.1 Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CmdPal: Primary command missing in context menu when initial command or command name is null

3 participants