Skip to content

Fix export/print when Preview Pane is hidden#274

Merged
schuyler merged 4 commits intomainfrom
claude/resolve-issue-16-Zc4jQ
Jan 15, 2026
Merged

Fix export/print when Preview Pane is hidden#274
schuyler merged 4 commits intomainfrom
claude/resolve-issue-16-Zc4jQ

Conversation

@schuyler
Copy link
Copy Markdown
Owner

Summary

  • Implements performAfterRender: mechanism to defer operations until WebView renders when preview pane is hidden
  • Fixes Copy HTML, Export HTML, Export PDF, and Print operations to use current document content
  • Adds 17 unit tests for the render deferral mechanism
  • Refactors existing copyHtml: fix to use the new general mechanism

Details

When the preview pane is hidden, needsHtml returns NO and the WebView doesn't render markdown changes. This caused export/print operations to output stale HTML. The fix queues operations in renderCompletionHandlers and triggers a render cycle, then invokes handlers when webView:didFinishLoadForFrame: or MathJax completion fires.

Test plan

  • CI passes on macOS 14, 15, 15-intel, and 26
  • Manual testing: Hide preview pane, type new content, export PDF - verify new content appears
  • Manual testing: Hide preview pane, type new content, print - verify new content prints
  • Manual testing: Hide preview pane, type new content, Copy HTML - verify clipboard has new content

Related to #16

Implements a general performAfterRender: mechanism that defers operations
until the WebView finishes rendering. This fixes issue #16 where PDF export,
HTML export, printing, and copy operations would use stale content when
the preview pane was hidden.

Changes:
- Add renderCompletionHandlers array property for queued operations
- Add performAfterRender: method to defer operations when preview hidden
- Add invokeRenderCompletionHandlers method called after WebView loads
- Update copyHtml: to use performAfterRender: (replaces copying flag)
- Update exportHtml: to defer HTML generation until after render
- Update printDocumentWithSettings: to defer print until after render
- Remove obsolete copying property and related code
- Add MPRenderDeferralTests.m with 17 tests for the mechanism

Related to #16
The method needs to be visible to the static function
MPGetPreviewLoadingCompletionHandler which is defined before
the @implementation block.

Related to #16
Add graceful skip logic when WebView doesn't render in headless CI
environment. The test now skips early if no display is available or
if handlers aren't invoked after toggling preview visibility.

Related to #16
- Fix methodSignatureForSelector: call to use printDelegate instead of
  NSMethodSignature class (was incorrect)
- Add weak-strong pattern to copyHtml: and exportHtml: blocks to prevent
  retain cycles when document is deallocated before render completes

Related to #16
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 14, 2026

Code Coverage Report

Current Coverage: 52.77%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       59.01% (7616/12906) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Document/MPDocument.m                                                      57.07% (1025/1796)  
        MPEditorPreferenceKeyWithValueKey                                                                                              85.71% (6/7)        
        MPEditorKeysToObserve                                                                                                          100.00% (15/15)     
        __MPEditorKeysToObserve_block_invoke                                                                                           100.00% (10/10)     
        MPEditorPreferencesToObserve                                                                                                   100.00% (13/13)     
        __MPEditorPreferencesToObserve_block_invoke                                                                                    100.00% (8/8)       
        MPRectStringForAutosaveName                                                                                                    100.00% (6/6)       
        MPAreNilableStringsEqual                                                                                                       100.00% (3/3)       
        MPGetWebViewBackgroundColor                                                                                                    0.00% (0/9)         
        -[NSURL(Convert) absoluteBaseURLString]                                                                                        0.00% (0/6)         
        -[WebView(Shortcut) enclosingScrollView]                                                                                       100.00% (3/3)       
        -[MPPreferences(Hoedown) extensionFlags]                                                                                       75.00% (21/28)      
        -[MPPreferences(Hoedown) rendererFlags]                                                                                        75.00% (9/12)       
        MPGetPreviewLoadingCompletionHandler                                                                                           100.00% (26/26)     
        __MPGetPreviewLoadingCompletionHandler_block_invoke                                                                            100.00% (23/23)     
        -[MPDocument preferences]                                                                                                      100.00% (3/3)       
        -[MPDocument markdown]                                                                                                         100.00% (3/3)       
        -[MPDocument setMarkdown:]                                                                                                     100.00% (3/3)       
        -[MPDocument html]                                                                                                             0.00% (0/3)         
        -[MPDocument toolbarVisible]                                                                                                   0.00% (0/3)         
        -[MPDocument previewVisible]                                                                                                   100.00% (3/3)       
        -[MPDocument editorVisible]                                                                                                    100.00% (3/3)       
        -[MPDocument needsHtml]                                                                                                        80.00% (4/5)        
        -[MPDocument setTotalWords:]                                                                                                   0.00% (0/7)         
        -[MPDocument setTotalCharacters:]                                                                                              0.00% (0/7)         
        -[MPDocument setTotalCharactersNoSpaces:]                                                                                      0.00% (0/8)         
        -[MPDocument setAutosaveName:]                                                                                                 100.00% (4/4)       
        -[MPDocument init]                                                                                                             90.00% (9/10)       
        -[MPDocument windowNibName]                                                                                                    100.00% (3/3)       
        -[MPDocument windowControllerDidLoadNib:]                                                                                      100.00% (88/88)     
        __41-[MPDocument windowControllerDidLoadNib:]_block_invoke                                                                     100.00% (4/4)       
        -[MPDocument reloadFromLoadedString]                                                                                           100.00% (8/8)       
        -[MPDocument close]                                                                                                            0.00% (0/20)        
        +[MPDocument autosavesInPlace]                                                                                                 100.00% (2/2)       
        +[MPDocument writableTypes]                                                                                                    100.00% (3/3)       
        -[MPDocument isDocumentEdited]                                                                                                 100.00% (5/5)       
        -[MPDocument writeToURL:ofType:error:]                                                                                         0.00% (0/15)        
        -[MPDocument dataOfType:error:]                                                                                                100.00% (3/3)       
        -[MPDocument readFromData:ofType:error:]                                                                                       100.00% (8/8)       
        -[MPDocument prepareSavePanel:]                                                                                                76.92% (30/39)      
        __31-[MPDocument prepareSavePanel:]_block_invoke                                                                               100.00% (12/12)     
        -[MPDocument printInfo]                                                                                                        0.00% (0/12)        
        -[MPDocument printOperationWithSettings:error:]                                                                                0.00% (0/7)         
        -[MPDocument printDocumentWithSettings:showPrintPanel:delegate:didPrintSelector:contextInfo:]                                  0.00% (0/24)        
        __93-[MPDocument printDocumentWithSettings:showPrintPanel:delegate:didPrintSelector:contextInfo:]_block_invoke                 0.00% (0/17)        
        -[MPDocument validateUserInterfaceItem:]                                                                                       0.00% (0/41)        

... (2469 more lines truncated)

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

@schuyler
Copy link
Copy Markdown
Owner Author

Closes #16

@schuyler schuyler merged commit 9ff46b3 into main Jan 15, 2026
9 checks passed
@schuyler schuyler deleted the claude/resolve-issue-16-Zc4jQ branch January 15, 2026 01:44
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.

2 participants