Overview
While Sync Folds automatically manages fold states in the background, it provides two manual commands for advanced use cases and troubleshooting.Available Commands
Export Folds from Local Storage
Manually exports all current fold states from localStorage to the settings file.
Import Folds into Local Storage
Manually imports fold states from the settings file to localStorage.
Export Folds from Local Storage
Command Details
- Command ID:
export-fold-states - Command Name: Export folds from local storage
- Source: main.ts:38-45
What It Does
This command reads all fold states currently stored in your browser’s localStorage and writes them to.obsidian/plugins/sync-folds/data.json. This is the same operation that happens automatically when you fold/unfold content (after the debounce period).
When to Use It
Forcing an immediate sync
Forcing an immediate sync
The plugin debounces fold state changes by 150ms. If you want to force an immediate write to disk (for example, before closing Obsidian on an unreliable sync connection), use this command.
Recovering from localStorage corruption
Recovering from localStorage corruption
If your fold states in the file got corrupted but localStorage still has good data, this command can rebuild the file from localStorage.
Initial setup on an existing vault
Initial setup on an existing vault
When you first install the plugin on a device that already has fold states in localStorage, the plugin automatically exports on load. However, if you disabled sync initially and want to export later, use this command.
How to Invoke
- Command Palette
- Hotkey
- Press
Ctrl+P(orCmd+Pon Mac) to open the command palette - Type “export folds” to filter commands
- Select Export folds from local storage
- You’ll see a notice: “Fold states saved to settings”
What Gets Exported
The command scans localStorage for all keys matching the pattern:- The file path
- The fold state data (array of folded regions and line count)
folds setting as a JSON string.
The export operation is logged in the console when DEBUG mode is enabled. You can verify what was exported by checking the developer console.
Import Folds into Local Storage
Command Details
- Command ID:
import-fold-states - Command Name: Import folds into local storage
- Source: main.ts:47-54
What It Does
This command reads all fold states from.obsidian/plugins/sync-folds/data.json and writes them to localStorage. This makes the fold states immediately available to Obsidian.
When to Use It
After manually editing data.json
After manually editing data.json
If you manually edit the plugin’s
data.json file (for example, to merge fold states from multiple devices), use this command to apply the changes to localStorage.Forcing a re-sync from the file
Forcing a re-sync from the file
If localStorage fold states seem out of sync with what’s in the file, this command forces a full re-import from the source of truth (the file).
Testing or recovery scenarios
Testing or recovery scenarios
During development, testing, or recovery from data loss, you might want to manually restore fold states from a backup
data.json.How to Invoke
- Command Palette
- Hotkey
- Press
Ctrl+P(orCmd+Pon Mac) to open the command palette - Type “import folds” to filter commands
- Select Import folds into local storage
- You’ll see a notice: “Fold states applied from settings”
What Gets Imported
The command reads thefolds setting from data.json, parses the JSON string, and writes each fold state to localStorage:
The import uses the original (non-intercepted)
setItem method to avoid triggering the debounced sync logic. This prevents an infinite loop where importing triggers an export.Command Comparison
- Export vs Import
- Automatic vs Manual
| Aspect | Export | Import |
|---|---|---|
| Direction | localStorage → file | file → localStorage |
| Source of truth | localStorage | data.json |
| Triggers auto-sync | No | No |
| Updates cache | Yes | Yes |
| Common use case | Force immediate save | Apply synced changes |
Common Workflows
Merging Fold States from Multiple Devices
Export from both devices
On each device, run Export folds from local storage to ensure the latest fold states are in each device’s
data.json.Manually merge the files
Copy the
folds JSON from both files and merge them in a text editor. The folds field is a JSON string, so you’ll need to parse it, merge the objects, and stringify again.Place merged file on both devices
Replace
.obsidian/plugins/sync-folds/data.json on both devices with your merged version.Recovering from a Conflict
Identify the good copy
Determine which device has the correct fold states. Open a file and check if folds are as expected.
Export from the good device
On the device with good fold states, run Export folds from local storage.
Troubleshooting
Command doesn't appear in palette
Command doesn't appear in palette
Ensure the plugin is enabled in Settings → Community plugins. If
enableSync is set to false, the commands are still registered, but the plugin won’t intercept fold changes automatically.Fold states don't apply after import
Fold states don't apply after import
Close and reopen the file. Obsidian reads fold states from localStorage when opening a file, not continuously. If the file is already open, the import won’t visually affect it until you close and reopen.
Export says 'Fold states saved' but file unchanged
Export says 'Fold states saved' but file unchanged
Check if
enableSync is true in the plugin settings. If sync is disabled, the export command will skip the write operation. Also check file permissions on data.json.