Phase B: Fix OptionSelector mutual exclusivity broken by dispatch mechanism#61
Closed
Copilot wants to merge 179 commits intov2_developfrom
Closed
Phase B: Fix OptionSelector mutual exclusivity broken by dispatch mechanism#61Copilot wants to merge 179 commits intov2_developfrom
Copilot wants to merge 179 commits intov2_developfrom
Conversation
- Add POST-GENERATION-VALIDATION.md with comprehensive checklist for validating AI-generated code before commits - Add formatting.md with detailed spacing, brace, and blank line rules - Update REFRESH.md to reference the validation checklist - Update CLAUDE.md with references to new validation docs These additions address the most common formatting violations that AI agents make when writing code for Terminal.Gui. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add clean-code-review.md task guide for reimplementing branches with narrative-quality commit histories - Remove scenario-modernization.md (outdated task) The clean code review task provides a workflow for AI agents to reimplement messy branch histories into clean, reviewer-friendly commit sequences suitable for PR review. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Addresses: gui-cs#4473 (Menu etc. with Selectors are broken) - Add command-propagation-plan.md with phased implementation plan - Remove command-propagation-analysis.md (superseded by plan) The plan introduces PropagatedCommands property to enable opt-in command propagation from SubViews to SuperViews, solving the issue where commands from nested views (e.g., FlagSelector in MenuBar) don't reach their containing views. Phase breakdown: 1. Foundation - PropagatedCommands infrastructure 2. WeakReference - Lifecycle-safe CommandContext.Source 3. Shortcut propagation - Enable Command.Activate for Shortcuts 4. Test cleanup - Re-enable skipped tests 5. MenuBar propagation - Full menu hierarchy support (deferred) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Addresses: gui-cs#4473 (Menu etc. with Selectors are broken) This commit implements Phases 1 and 2 of the command propagation plan: Phase 1 - PropagatedCommands Infrastructure: - Add PropagatedCommands property to View (default: [Command.Accept]) - Add PropagateCommand helper method for command bubbling - Refactor RaiseAccepting to use PropagateCommand helper - Reorganize View.Command.cs regions for clarity Phase 2 - WeakReference for CommandContext.Source: - Change ICommandContext.Source from View? to WeakReference<View>? - Update CommandContext to use WeakReference for lifecycle safety - Update InvokeCommand overloads to wrap 'this' in WeakReference - Update all views using ctx.Source to use TryGetTarget pattern: - Dialog, DialogTResult - MenuBar, PopoverMenu - ComboBox, OptionSelector - ScrollSlider, Shortcut The PropagatedCommands property enables opt-in command propagation: when a SubView raises a command that isn't handled and the command is in the SuperView's PropagatedCommands list, the command bubbles up. BREAKING CHANGE: ICommandContext.Source is now WeakReference<View>? Code accessing ctx.Source must use TryGetTarget pattern: if (ctx?.Source?.TryGetTarget (out View? view) == true) { ... } Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add a standalone test application for verifying Command.Activate propagation through the Shortcut → Window hierarchy. The example demonstrates: - CheckBox (CanFocus=false) in Shortcut → propagates to Window - CheckBox (CanFocus=true) in Shortcut → propagates to Window - Button in Shortcut → propagates to Window This serves as a manual test bed for the PropagatedCommands feature and helps verify that command context (Source) is properly preserved when commands bubble up through the view hierarchy. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests to verify PropagatedCommands and WeakReference changes: CommandPropagationTests.cs (NEW - 588 lines): - Tests for command propagation through view hierarchies - Tests for WeakReference lifecycle safety - Tests for PropagatedCommands customization - Tests for Command.Accept and Command.Activate propagation ViewCommandTests.cs (updated): - Add tests for PropagatedCommands default value - Add tests for PropagateCommand helper behavior - Add tests for IsDefault button propagation CommandContextTests.cs (updated): - Update tests for WeakReference-based Source property - Add TryGetTarget pattern tests InputBindingTests.cs (updated): - Update tests for WeakReference compatibility All tests follow Terminal.Gui patterns and are added to UnitTestsParallelizable for parallel execution. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
command.md: - Document PropagatedCommands property - Explain command propagation behavior - Add examples for customizing propagated commands events.md: - Add section on command events and propagation - Document CommandEventArgs and ICommandContext - Explain WeakReference pattern for Source property Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update scenarios to use TryGetTarget pattern for accessing CommandContext.Source after the WeakReference change: Menus.cs: - Update command handlers to use TryGetTarget MouseTester.cs: - Update mouse event handlers for new pattern UICatalogRunnable.cs: - Update command context handling Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change absolute path to relative path for cross-machine compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Clarify and strengthen event forwarding between Shortcut and its CommandView, ensuring Activating and Accepting events propagate correctly without recursion. MouseHighlightStates now defaults to MouseState.In for better UI feedback. Refactor property implementations and clean up code. Add comprehensive unit tests verifying CheckBox state changes, event propagation, and default behaviors. Enhance ShortcutTestWindow to log detailed event info and demonstrate propagation scenarios.
- Updated Key equality operators to handle nulls safely and avoid NullReferenceExceptions. - ComboBox Accept command now uses non-nullable View in TryGetTarget and passes a WeakReference<View> to CommandContext for consistency. - Shortcut.Key property now always returns Key.Empty if unset, and setter no longer throws on null. - Simplified GetWidthDimAuto by removing unnecessary null-forgiving operators. - Fixed CommandViewOnActivating logic to prevent recursion and ensure correct event propagation. - Cleaned up redundant key initialization and clarified KeyView.Text assignment. - Overall, these changes improve code safety, event handling, and clarity.
Refactored the Shortcut class to replace explicit backing fields (_alignmentModes and _minimumKeyTextSize) with auto-implemented properties for AlignmentModes and MinimumKeyTextSize. Set default values directly in the property declarations and used the C# field keyword in setters. This streamlines property definitions and simplifies the codebase.
…/Terminal.Gui into copilot/fix-command-propagation-issue-clean
…/Terminal.Gui into copilot/fix-command-propagation-issue-clean
Improve command/event handling for menus and shortcuts Refactor Shortcut, Menu, MenuBar, and PopoverMenu to enhance command propagation, event handling, and resource management. Set PropagatedCommands by default, improve design-time support, and clarify event subscriptions. Add helper methods for event origin detection, enforce proper menu hierarchy, and update documentation and logging for better maintainability and debugging.
…/Terminal.Gui into copilot/fix-command-propagation-issue-clean
Renames PropagatedCommands to CommandsToBubbleUp for clarity and consistency across all view classes. Command bubbling (for Accept/Activate) is now opt-in via this property; by default, no commands bubble up. Event handling is clarified: Accepted is only raised if Accepting is not handled, and bubbling only occurs for commands listed in CommandsToBubbleUp. Updates all affected classes, refactors and expands tests to cover new bubbling logic, and revises documentation and planning guides. This is a breaking change for code using the old PropagatedCommands property.
Pressing Enter now triggers Accepted event in single-line mode. Accept command is no longer added but returns true when invoked. Tests updated for new behavior. Minor list initialization cleanup.
…mmutable CommandContext, WeakReference bindings) Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement phases A-E of the plan
Phase A: Command System Foundation Types - Immutable Context, Routing Enum, WeakReference Bindings
Feb 19, 2026
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot
AI
changed the title
Phase A: Command System Foundation Types - Immutable Context, Routing Enum, WeakReference Bindings
Phase A: Command System Foundation - Immutable Context, Routing Enum, WeakReference Bindings
Feb 19, 2026
…i into copilot/excellent-tyrannosaurus
…elector, FlagSelector Co-authored-by: tig <585482+tig@users.noreply.github.com>
…cut tests failing) Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot
AI
changed the title
Phase A: Command System Foundation - Immutable Context, Routing Enum, WeakReference Bindings
Phase A-B: Command System Redesign - Foundation Types and Dispatch Mechanism
Feb 19, 2026
…ll failing) Co-authored-by: tig <585482+tig@users.noreply.github.com>
…passing Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot
AI
changed the title
Phase A-B: Command System Redesign - Foundation Types and Dispatch Mechanism
Implement Phase A-B: Command System Foundation & Dispatch Mechanism
Feb 19, 2026
…ubscription pattern Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot
AI
changed the title
Implement Phase A-B: Command System Foundation & Dispatch Mechanism
Phase B: Fix OptionSelector mutual exclusivity broken by dispatch mechanism
Feb 19, 2026
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.
Proposed Changes/Todos
Phase B dispatch mechanism broke OptionSelector's mutual exclusivity - clicking a non-active item would activate it without deactivating others. Root cause: removed
OnActivatingoverride and CheckBox event subscriptions that managed shared selection state.Changes
OnActivatingoverride - Applies value change when CheckBox bubbles or direct command invokes, callsUpdateChecked()to synchronize all CheckBox statesCheckBox.Activating, invoke command on OptionSelector, setargs.Handled = trueto prevent CheckBox from toggling itself (OptionSelector owns selection state)OnHandlingHotKeyoverride - Restores HotKey cycling behaviorGetDispatchTargetreturns null when command already bubbling from CheckBox subview (prevents double-processing)CommandRouting.DispatchingDownto avoid infinite recursion when OptionSelector dispatches to CheckBoxKey Insight
Views with
ConsumeDispatch = truethat own shared state must subscribe to subview events to intercept commands and centrally apply state changes. Prevents subviews from independently modifying shared state.Test Results
Remaining 6 failures are edge cases involving direct command invocation and nested consume/relay view interactions.
Pull Request checklist:
dotnet testbefore commit///style comments)Original prompt
Implement Phases A-E of the plan
**Chronological Review:** 1. User asked agent to act like an Amazon PE and review a design document in `./plans` 2. Agent found and read `plans/command-system-redesign-requirements.md` - a comprehensive Terminal.Gui v2 Command System redesign document 3. Agent fetched Amazon PE tenets page (minimal content returned) 4. Agent dispatched an explore task to understand the current codebase implementation across 8 key files 5. Agent directly viewed `View.Command.cs`, `CommandContext.cs`, `ICommandContext.cs`, `ICommandBinding.cs` to validate claims 6. Agent viewed specific sections of `View.Command.cs` (DefaultAcceptHandler, RaiseAccepting, DefaultActivateHandler, RaiseActivating, TryBubbleUp, BubbleDown) 7. Agent grepped Shortcut.cs and FlagSelector.cs to validate deletion claims 8. Agent delivered a comprehensive PE-level review with 5 critical issues, 4 gaps, and minor nits 9. User responded with gap resolutions and said "/delegate Implement Phases A-E of the plan" 10. User provided PR link: https://github.com/gui-cs/pull/4620 11. Agent read the PR details (massive PR: 161 commits, 183 files, +15876/-9760 lines) 12. Agent checked git branch (copilot/fix-command-propagation-issue-clean) and status 13. User reported `/delegate` error: "Could not determine GitHub repository from git remotes" 14. Agent diagnosed malformed git remotes (SSH aliases `tig:` instead of standard URLs) 15. Agent fixed remotes to use HTTPS URLs, told user to retry `/delegate`Intent Mapping:
Technical Inventory:
Commandsystem and FixMenus gui-cs/Terminal.Gui#4620 on branchcopilot/fix-command-propagation-issue-cleanCode Archaeology:
View.Command.cs(~819 lines): Core command handling with bool? tri-state, RaiseActivating/RaiseAccepting/TryBubbleUp/BubbleDownCommandContext.cs: Mutable record struct with Command/Source/Binding/IsBubblingUp/IsBubblingDownICommandContext.cs: Interface with mutable Command set accessorICommandBinding.cs: Source isView?(strong ref) — inconsistent with context'sWeakReference<View>?Shortcut.cs(~950 lines): Complex HandleActivate, deferred activation flags, CommandView_Activated wiringFlagSelector.cs: _suppressHotKeyActivate temporal coupling, OnActivating with 3 mixed concernsOptionSelector.cs: OnActivating override consuming bubblePopoverMenu.cs: Manual event subscription across boundariesMenuBarItem.cs: Event wiring in property setters, commented-out RaiseActivatedProgress Assessment:
Context Validation:
The user wants to delegate implementation of Phases A-E to Copilot coding agents. The git remote issue was blocking this and has been fixed.
Recent Commands Analysis:
github-mcp-server-pull_request_read- Read PR Fixes #4473 - Re-engineerCommandsystem and FixMenus gui-cs/Terminal.Gui#4620 details (open, 161 commits, 183 files, mergeable, on branchcopilot/fix-command-propagation-issue-clean, base:v2_develop)powershell-git branch --show-current && git status --short→ branch iscopilot/fix-command-propagation-issue-clean, one deleted file in statuspowershell-git remote -v→ Found malformed remotes using SSH aliastig:powershell-git remote set-url origin/upstream→ Fixed to HTTPS URLs1. Conversation Overview: - Primary Objectives: User asked agent to "Act like an amazon PE" and review `./plans/command-system-redesign-requirements.md` — a comprehensive Terminal.Gui v2 Command System redesign plan. After the review, user provided gap resolutions and requested: "/delegate Implement Phases A-E of the plan" targeting PR gui-cs#4620. - Session Context: Agent performed a thorough PE-level architecture review of an 8-change, 5-phase command system redesign. The review identified 5 critical issues, 4 gaps, and minor nits. User resolved all gaps and attempted to delegate implementation to Copilot coding agents, but hit a git remote configuration issue whi...
Created from Copilot CLI via the copilot delegate command.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.