Skip to content

Add auto-save preference to control document auto-save behavior#326

Merged
schuyler merged 1 commit into
mainfrom
claude/research-macdown-autosave-qjDUU
Feb 26, 2026
Merged

Add auto-save preference to control document auto-save behavior#326
schuyler merged 1 commit into
mainfrom
claude/research-macdown-autosave-qjDUU

Conversation

@schuyler

@schuyler schuyler commented Feb 24, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds a new editorAutoSave preference that allows users to control whether MacDown automatically saves and reloads documents. Previously, auto-save was always enabled. This change makes it configurable while preserving the existing behavior for current users through a migration.

Key Changes

  • New Preference Property: Added editorAutoSave boolean property to MPPreferences that defaults to YES for new and existing users
  • Migration System: Implemented migration version 4 to ensure existing users at version 3 get editorAutoSave defaulted to YES, preserving their current auto-save behavior
  • Document Auto-save Control: Modified MPDocument.autosavesInPlace to respect the preference instead of always returning YES
  • External File Change Handling: Updated handleExternalFileChange to always prompt for reload when auto-save is disabled, giving users explicit control over external file changes
  • UI Addition: Added "Auto-save and auto-reload documents" checkbox to the General preferences window in the Behavior section
  • Comprehensive Tests:
    • Added testAutoSaveToggle to verify preference persistence
    • Added testAutoSaveMigrationDefaultsToYes to verify migration behavior
    • Updated existing auto-save tests to verify preference-based behavior instead of assuming it's always enabled

Implementation Details

  • The preference is stored in NSUserDefaults with key editorAutoSave
  • Default value is YES for both new installations and users migrating from version 3
  • The preference is bound to the UI checkbox via Cocoa bindings
  • When auto-save is disabled, external file changes trigger a user prompt instead of silent reload, ensuring users maintain control of their editor state

@schuyler schuyler force-pushed the claude/research-macdown-autosave-qjDUU branch from 2bb1235 to 8f507d8 Compare February 24, 2026 18:04
@github-actions

github-actions Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Current Coverage: 56.42%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       59.68% (8166/13682) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Document/MPDocument.m                                                      54.67% (1107/2025)  
        MPEditorPreferenceKeyWithValueKey                                                                                              85.71% (6/7)        
        MPEditorKeysToObserve                                                                                                          100.00% (15/15)     
        __MPEditorKeysToObserve_block_invoke                                                                                           100.00% (10/10)     
        MPEditorPreferencesToObserve                                                                                                   100.00% (14/14)     
        __MPEditorPreferencesToObserve_block_invoke                                                                                    100.00% (9/9)       
        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]                                                                                       78.57% (22/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% (99/99)     
        __41-[MPDocument windowControllerDidLoadNib:]_block_invoke                                                                     100.00% (3/3)       
        __41-[MPDocument windowControllerDidLoadNib:]_block_invoke.56                                                                  100.00% (6/6)       
        -[MPDocument reloadFromLoadedString]                                                                                           100.00% (8/8)       
        -[MPDocument close]                                                                                                            13.33% (4/30)       
        +[MPDocument autosavesInPlace]                                                                                                 100.00% (3/3)       
        +[MPDocument writableTypes]                                                                                                    100.00% (3/3)       
        -[MPDocument isDocumentEdited]                                                                                                 100.00% (5/5)       
        -[MPDocument writeToURL:ofType:error:]                                                                                         0.00% (0/28)        
        __38-[MPDocument writeToURL:ofType:error:]_block_invoke                                                                        0.00% (0/2)         
        __38-[MPDocument writeToURL:ofType:error:]_block_invoke_2                                                                      0.00% (0/3)         
        -[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)         

... (2784 more lines truncated)

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

Adds an editorAutoSave preference (default: YES) that controls both
NSDocument autosave-in-place and auto-reload behavior. When disabled,
autosave-in-place is turned off and external file changes always prompt
the user instead of silently reloading.

Includes preference migration (version 4) to default existing users to
YES, a checkbox in General preferences, and updated tests.

https://claude.ai/code/session_01CZuWu6Y2w3GynDb8dZyuHs
@schuyler schuyler force-pushed the claude/research-macdown-autosave-qjDUU branch from 8f507d8 to d2e698c Compare February 26, 2026 19:09
@schuyler schuyler merged commit 6d47ac5 into main Feb 26, 2026
9 checks passed
@schuyler schuyler deleted the claude/research-macdown-autosave-qjDUU branch February 26, 2026 20:00
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