fix: reset the zoom to the font size chosen in Appearance

Ctrl+0 reset the editor font to a fixed 14 px, because zooming overwrote
the size chosen in Appearance. That choice is now kept separately and
Ctrl+0 returns to it. For existing installs the size in use at first
launch becomes the preference.

Refs #272
This commit is contained in:
Yuri Karamian committed 2026-10-10 13:34:39 +02:00
1 parent 8df5efacb8
commit 2014365e4a
6 files changed
+65 -7

No files matched your search

+49 -2
View File
@@ -569,9 +569,18 @@ pub fn import_custom_themes(
}
#[tauri::command]
pub fn set_font_size(app: AppHandle, state: State<'_, AppState>, size: u32) -> Result<(), String> {
pub fn set_font_size(
app: AppHandle,
state: State<'_, AppState>,
size: u32,
preferred: Option<bool>,
) -> Result<(), String> {
let mut config = state.config.lock().map_err(|e| e.to_string())?;
config.font_size = Some(size);
// Only a choice made in Appearance becomes the size that resetting the zoom returns to.
if preferred == Some(true) {
config.preferred_font_size = Some(size);
}
save_app_config(&config)?;
drop(config);
@@ -4222,12 +4231,24 @@ pub fn load_app_config() -> AppConfig {
.and_then(|p| std::fs::read_to_string(p).ok())
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or_default();
if migrate_global_sync_to_vault(&mut config) {
let migrated_sync = migrate_global_sync_to_vault(&mut config);
let migrated_font = adopt_font_size_as_preference(&mut config);
if migrated_sync || migrated_font {
let _ = save_app_config(&config);
}
config
}
// One-time migration: the size in use when the preference was introduced becomes the preference,
// so resetting the zoom does not fall back to the built-in default for existing users.
fn adopt_font_size_as_preference(config: &mut AppConfig) -> bool {
if config.preferred_font_size.is_some() || config.font_size.is_none() {
return false;
}
config.preferred_font_size = config.font_size;
true
}
// One-time migration: WebDAV sync moved from global AppConfig to per-vault VaultConfig.
// Copy the old global settings into the active vault's config if it has none yet. Idempotent.
fn migrate_global_sync_to_vault(config: &mut AppConfig) -> bool {
@@ -4368,6 +4389,32 @@ pub fn get_install_type() -> String {
}
}
#[cfg(test)]
mod font_size_preference_tests {
use super::*;
#[test]
fn current_size_becomes_the_preference_once() {
let mut config = AppConfig {
font_size: Some(18),
..AppConfig::default()
};
assert!(adopt_font_size_as_preference(&mut config));
assert_eq!(config.preferred_font_size, Some(18));
// A later zoom changes only the size in use.
config.font_size = Some(22);
assert!(!adopt_font_size_as_preference(&mut config));
assert_eq!(config.preferred_font_size, Some(18));
}
#[test]
fn nothing_is_adopted_without_a_saved_size() {
let mut config = AppConfig::default();
assert!(!adopt_font_size_as_preference(&mut config));
assert_eq!(config.preferred_font_size, None);
}
}
#[cfg(test)]
mod vault_runtime_tests {
use super::*;
+5
View File
@@ -163,6 +163,10 @@ pub struct AppConfig {
pub accent_color: Option<String>,
#[serde(default)]
pub font_size: Option<u32>,
/// The size chosen in Appearance. Zooming changes `font_size` only, and resetting the zoom
/// returns to this.
#[serde(default)]
pub preferred_font_size: Option<u32>,
#[serde(default = "default_true")]
pub scroll_to_change_font_size: bool,
#[serde(default)]
@@ -337,6 +341,7 @@ impl Default for AppConfig {
system_dark_theme: default_system_dark_theme(),
accent_color: None,
font_size: None,
preferred_font_size: None,
scroll_to_change_font_size: true,
toolbar_layout: None,
font_family: None,