Skip to content

Fix toolbar buttons not dispatching when editor has focus#496

Merged
schuyler merged 2 commits into
mainfrom
claude/fix-toolbar-dispatch-278-01Y4ommV4yZoApvin8ddozbw
Jul 1, 2026
Merged

Fix toolbar buttons not dispatching when editor has focus#496
schuyler merged 2 commits into
mainfrom
claude/fix-toolbar-dispatch-278-01Y4ommV4yZoApvin8ddozbw

Conversation

@schuyler

@schuyler schuyler commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Standalone toolbar buttons and dropdown menu items set target = self.document during init, but the weak IBOutlet isn't connected until after init — leaving target nil. Actions went through the responder chain, which worked from the preview pane but failed from the editor pane.
  • Route standalone and dropdown items through the toolbar controller (matching the pattern already used for grouped items via selectedToolbarItemGroupItem:), dispatching to self.document at invocation time when the outlet is connected.
  • Add validateUserInterfaceItem: forwarding on the toolbar controller so dropdown menu items (Layout) still get dynamic titles and enable/disable state from the document.

Test plan

  • 13 new unit tests covering standalone and dropdown dispatch, action mapping correctness, and crash-freedom for edge cases
  • All 1039 tests pass (0 unexpected failures)
  • Manual: focus editor pane → click Insert Table → table appears
  • Manual: Layout dropdown shows correct titles (Hide/Restore Editor/Preview Pane)
  • CI passes

Related to #278

schuyler added 2 commits June 30, 2026 15:51
Standalone toolbar buttons and dropdown menu items set target = self.document
during init, but the weak IBOutlet isn't connected until after init, leaving
target nil. Actions then went through the responder chain, which worked from
the preview pane but failed from the editor pane.

Route standalone and dropdown items through the toolbar controller (matching
the pattern already used for grouped items), dispatching to self.document at
invocation time when the outlet is connected.

Related to #278
Dropdown menu items now target the toolbar controller with a generic
dropdownMenuItemClicked: action, so MPDocument's validateUserInterfaceItem:
can no longer identify them by action selector. Forward validation by
temporarily restoring the real action (from representedObject) before
calling the document's validation.

Related to #278
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Current Coverage: 63.11%

Coverage Details (Summary)
Name                                                                                                                                   Coverage             
-------------------------------------------------------------------------------------------------------------------------------------- -------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)          
MacDown 3000.app                                                                                                                       63.93% (9353/14629)  
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Preferences/MPHtmlPreferencesViewController.m                              0.00% (0/113)        
        MPPrismDefaultThemeName                                                                                                        0.00% (0/2)          
        -[MPHtmlPreferencesViewController viewIdentifier]                                                                              0.00% (0/3)          
        -[MPHtmlPreferencesViewController toolbarItemImage]                                                                            0.00% (0/3)          
        -[MPHtmlPreferencesViewController toolbarItemLabel]                                                                            0.00% (0/2)          
        -[MPHtmlPreferencesViewController viewWillAppear]                                                                              0.00% (0/4)          
        -[MPHtmlPreferencesViewController changeStylesheet:]                                                                           0.00% (0/7)          
        -[MPHtmlPreferencesViewController changeHighlightingTheme:]                                                                    0.00% (0/7)          
        -[MPHtmlPreferencesViewController invokeStylesheetFunction:]                                                                   0.00% (0/23)         
        -[MPHtmlPreferencesViewController invokeHighlightingThemeFunction:]                                                            0.00% (0/33)         
        -[MPHtmlPreferencesViewController loadStylesheets]                                                                             0.00% (0/14)         
        -[MPHtmlPreferencesViewController loadHighlightingThemes]                                                                      0.00% (0/15)         
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/NSColor+HTML.m                                                   94.05% (332/353)     
        +[NSColor(HTML) colorWithHexString:]                                                                                           94.12% (16/17)       
        +[NSColor(HTML) colorWithHTMLName:]                                                                                            89.13% (164/184)     
        __35+[NSColor(HTML) colorWithHTMLName:]_block_invoke                                                                           100.00% (152/152)    
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Utility/FileURLInlining.m                                                  26.60% (25/94)       
        +[FileURLInlining inlineFromIterable:]                                                                                         0.00% (0/11)         
        -[FileURLInlining initWithURL:]                                                                                                0.00% (0/6)          
        -[FileURLInlining init]                                                                                                        100.00% (3/3)        
        -[FileURLInlining inlineContent]                                                                                               0.00% (0/9)          
        -[FileURLInlining imageContent]                                                                                                0.00% (0/12)         
        +[FileURLInlining mimeTypeForFilePath:]                                                                                        100.00% (22/22)      
        -[FileURLInlining clippingContent]                                                                                             0.00% (0/4)          
        +[FileURLInlining isTextClippingAtPath:]                                                                                       0.00% (0/12)         
        +[FileURLInlining textContentFromClipping:]                                                                                    0.00% (0/15)         
    /Users/runner/work/macdown3000/macdown3000/Dependency/peg-markdown-highlight/HGMarkdownHighlightingStyle.m                         89.23% (58/65)       
        +[HGMarkdownHighlightingStyle colorFromARGBColor:]                                                                             100.00% (6/6)        
        -[HGMarkdownHighlightingStyle initWithType:attributesToAdd:toRemove:fontTraitsToAdd:]                                          88.89% (8/9)         
        -[HGMarkdownHighlightingStyle initWithStyleAttributes:baseFont:]                                                               88.00% (44/50)       
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Utility/MPResourceWatcherSet.m                                             93.75% (90/96)       
        -[MPResourceWatcherSet init]                                                                                                   100.00% (6/6)        
        -[MPResourceWatcherSet dealloc]                                                                                                0.00% (0/3)          
        -[MPResourceWatcherSet watchedPaths]                                                                                           100.00% (3/3)        
        -[MPResourceWatcherSet updateWatchedPaths:]                                                                                    100.00% (16/16)      
        -[MPResourceWatcherSet addWatcherForPath:]                                                                                     100.00% (34/34)      
        __42-[MPResourceWatcherSet addWatcherForPath:]_block_invoke                                                                    100.00% (6/6)        
        __42-[MPResourceWatcherSet addWatcherForPath:]_block_invoke.39                                                                 93.33% (14/15)       
        __42-[MPResourceWatcherSet addWatcherForPath:]_block_invoke_2                                                                  75.00% (6/8)         
        -[MPResourceWatcherSet stopAll]                                                                                                100.00% (5/5)        
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/hoedown_html_patch.c                                             91.39% (191/209)     
        hoedown_patch_reset_checkbox_index                                                                                             100.00% (3/3)        
        new_growable_buffer                                                                                                            100.00% (3/3)        
        hoedown_patch_get_checkbox_index                                                                                               0.00% (0/3)          
        hoedown_patch_render_blockcode                                                                                                 89.09% (49/55)       
        hoedown_patch_render_listitem                                                                                                  100.00% (45/45)      

... (3450 more lines truncated)

📊 **Full coverage report available in workflow artifacts**

@schuyler schuyler merged commit dd8fb71 into main Jul 1, 2026
9 checks passed
@schuyler schuyler deleted the claude/fix-toolbar-dispatch-278-01Y4ommV4yZoApvin8ddozbw branch July 1, 2026 00:46
schuyler added a commit that referenced this pull request Jul 1, 2026
## Summary

- Standalone toolbar buttons and dropdown menu items set `target =
self.document` during `init`, but the weak IBOutlet isn't connected
until after init — leaving target nil. Actions went through the
responder chain, which worked from the preview pane but failed from the
editor pane.
- Route standalone and dropdown items through the toolbar controller
(matching the pattern already used for grouped items via
`selectedToolbarItemGroupItem:`), dispatching to `self.document` at
invocation time when the outlet is connected.
- Add `validateUserInterfaceItem:` forwarding on the toolbar controller
so dropdown menu items (Layout) still get dynamic titles and
enable/disable state from the document.

## Test plan

- [x] 13 new unit tests covering standalone and dropdown dispatch,
action mapping correctness, and crash-freedom for edge cases
- [x] All 1039 tests pass (0 unexpected failures)
- [x] Manual: focus editor pane → click Insert Table → table appears
- [x] Manual: Layout dropdown shows correct titles (Hide/Restore
Editor/Preview Pane)
- [ ] CI passes

Related to #278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant