Auto-Save Feature
January 17, 2026 · View on GitHub
Overview
Ferrite implements a configurable auto-save feature that saves documents after a configurable idle delay. The feature uses a temp-file based strategy to prevent data loss without overwriting the main file prematurely.
Key Features
- Per-document toggle - Each tab can have auto-save enabled/disabled independently via toolbar button
- Settings-based defaults - New documents inherit auto-save state from settings
- Idle-based triggering - Saves after configurable idle delay (not interval-based)
- Temp file strategy - Writes to
.autosave/in config directory, not the main file - Recovery on open - Detects newer temp files and offers restore/discard
- Atomic writes - Uses temp file + rename for crash safety
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
auto_save_enabled_default | bool | false | Default auto-save state for new tabs |
auto_save_delay_ms | u32 | 15000 | Delay in ms before auto-save triggers |
Settings are configurable in the Settings panel under "Files" section.
Architecture
State Management
// Tab struct fields for auto-save
pub struct Tab {
pub auto_save_enabled: bool, // Per-tab toggle
pub last_edit_time: Option<Instant>, // For idle detection
last_auto_save_content_hash: Option<u64>, // Change detection
}
Key Methods
Tab::toggle_auto_save()- Toggle auto-save for this tabTab::mark_content_edited()- Called when content changes (updates last_edit_time)Tab::should_auto_save(delay_ms)- Check if auto-save should triggerTab::mark_auto_saved()- Mark content as auto-saved (updates hash)
Temp File Storage
Auto-save files are stored in:
~/.config/ferrite/autosave/
├── filename_<hash>.md.autosave # For saved files
└── untitled_<tab_id>.md.autosave # For unsaved documents
Each auto-save file contains:
- JSON metadata line (tab ID, original path, timestamp, content hash)
- Blank line separator
- Document content
Auto-Save Flow
- Content edited →
set_content()callsmark_content_edited() - Main loop →
process_auto_saves()checks each tab - If should_auto_save → Write to temp file,
mark_auto_saved() - Manual save →
cleanup_auto_save_for_tab()deletes temp file
Recovery Flow
- File opened →
check_auto_save_recovery()checks for newer temp file - If found → Store
AutoSaveRecoveryInfofor dialog - Update loop →
show_auto_save_recovery_dialog()renders modal - User chooses → Restore content or discard temp file
UI Components
Toolbar Button
Located in the File group of the ribbon:
- Icon: ⏱ (enabled) / ⏸ (disabled)
- Color: Green background when active
- Action:
RibbonAction::ToggleAutoSave
Settings Panel
Under "Files" section:
- Checkbox: "Enable Auto-Save by Default"
- Slider: Auto-save delay (5-300 seconds)
- Presets: 15s, 30s, 1m buttons
Recovery Dialog
Modal dialog shown when opening file with newer auto-save:
- Shows file path and time since auto-save
- Buttons: "✅ Restore" and "🗑 Discard"
Cleanup
Auto-save temp files are cleaned up:
- After manual save (via Save or Save As)
- After user discards recovery
- After user restores from recovery
Related Files
src/config/settings.rs- Settings definitionssrc/config/session.rs- Temp file functionssrc/state.rs- Tab auto-save statesrc/app.rs- Auto-save processing, recovery dialogsrc/ui/ribbon.rs- Toolbar toggle button
Testing
Manual Test Cases
- Enable auto-save, edit, wait > delay → Verify temp file created in config dir
- Manual save → Verify temp file cleared
- Crash simulation → Kill process, restart, open file → Verify recovery prompt
- Per-editor toggle → Verify independent auto-save state per tab
- Large file → Verify no UI lag during auto-save (atomic write)
Verify Temp File Location
Windows: %APPDATA%\ferrite\autosave\
Linux: ~/.config/ferrite/autosave/
macOS: ~/Library/Application Support/ferrite/autosave/