View Mode Persistence
December 19, 2025 ยท View on GitHub
Overview
Per-tab view mode persistence allows each tab to maintain its own view mode (Raw or Rendered) independently, with modes persisting across application restarts.
Key Files
src/config/settings.rs-TabInfostruct withview_modefield,ViewModeenumsrc/state.rs-Tabstruct with view mode methods, session restorationsrc/app.rs- Per-tab view mode usage in UI
Implementation Details
ViewMode Enum
Defined in settings.rs:
pub enum ViewMode {
Raw, // Plain markdown text editing
Rendered, // WYSIWYG rendered editing
}
Per-Tab Storage
View mode is stored at two levels:
- Runtime (
Tabstruct):view_mode: ViewModefield on each tab - Persistence (
TabInfostruct): Serialized to config JSON vialast_open_tabs
Default Behavior
| Scenario | Default Mode |
|---|---|
New tab created (Tab::new()) | Raw |
File opened (Tab::with_file()) | Raw |
Session restored (Tab::from_tab_info()) | Saved mode |
Old config (no view_mode field) | Raw (backward compatible) |
Tab Methods
impl Tab {
pub fn get_view_mode(&self) -> ViewMode;
pub fn set_view_mode(&mut self, mode: ViewMode);
pub fn toggle_view_mode(&mut self) -> ViewMode;
}
Session Persistence
On shutdown:
Tab::to_tab_info()includesview_modeAppState::save_settings_if_dirty()serializes to config
On startup:
Tab::from_tab_info()restores saved view mode- Missing
view_modefield defaults toRaw(serde default)
Config Format
{
"last_open_tabs": [
{
"path": "/path/to/file.md",
"modified": false,
"cursor_position": [0, 0],
"scroll_offset": 0.0,
"view_mode": "rendered"
}
]
}
Usage
Toggle View Mode (Active Tab)
// In app.rs
if let Some(tab) = self.state.active_tab_mut() {
let new_mode = tab.toggle_view_mode();
}
Get Current Tab's Mode
let view_mode = self.state.active_tab()
.map(|t| t.view_mode)
.unwrap_or(ViewMode::Raw);
Keyboard Shortcut
Ctrl+Shift+V toggles view mode for the active tab.
Tests
Run tests with:
cargo test view_mode
cargo test tab_from_tab_info
cargo test restore_session
Key tests:
test_tab_view_mode_toggle- Toggle functionalitytest_tab_view_mode_get_set- Getter/settertest_tab_info_backward_compatibility- Old config supporttest_restore_session_tabs_with_temp_file- Session restorationtest_restore_multiple_tabs_with_temp_files- Multi-tab persistence
Backward Compatibility
Old config files without view_mode in TabInfo will deserialize correctly due to #[serde(default)] attribute, defaulting to ViewMode::Raw.