M3.10: autosave and flushDirty

Autosave saves dirty buffers when the window loses focus (DOM blur and
visibilitychange), when the active tab changes and after
editor.autosave.idleSeconds (default 15) without an edit; three settings,
all on by default. flushDirty() in ui/src/stores/autosave.ts is the one
save-all-dirty-and-wait entry point for later deployment, run and
terminal features: it waits for pending buffer sync, then runs
file.saveAll {skipConflicts: true}; one toast per failed file.

Engine: file.saveAll takes skipConflicts and returns skipped; Buffers
tracks buffers in conflict with their file and the hash of the last
read/written content, so our own save reported late is not a conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-20 20:59:44 +02:00
parent 228669036c
commit e1dc24dc25
18 changed files with 996 additions and 37 deletions

View file

@ -224,6 +224,30 @@ pub const DEFS: &[Def] = &[
description_key: "settings.phpactor.autoDownload.description",
section: "php",
},
Def {
key: "editor.autosave.onBlur",
kind: Kind::Bool,
default: DefaultValue::Bool(true),
label_key: "settings.editor.autosave.onBlur.label",
description_key: "settings.editor.autosave.onBlur.description",
section: "editor",
},
Def {
key: "editor.autosave.onTabSwitch",
kind: Kind::Bool,
default: DefaultValue::Bool(true),
label_key: "settings.editor.autosave.onTabSwitch.label",
description_key: "settings.editor.autosave.onTabSwitch.description",
section: "editor",
},
Def {
key: "editor.autosave.idleSeconds",
kind: Kind::Int { min: 0, max: 600 },
default: DefaultValue::Int(15),
label_key: "settings.editor.autosave.idleSeconds.label",
description_key: "settings.editor.autosave.idleSeconds.description",
section: "editor",
},
];
/// Looks a known setting up by key.
@ -584,6 +608,29 @@ mod tests {
assert_eq!(s.get("editor.fontSize"), Some(json!(14)));
}
#[test]
fn autosave_defaults_and_validation() {
let mut s = Settings::in_memory();
assert_eq!(s.get("editor.autosave.onBlur"), Some(json!(true)));
assert_eq!(s.get("editor.autosave.onTabSwitch"), Some(json!(true)));
assert_eq!(s.get("editor.autosave.idleSeconds"), Some(json!(15)));
assert_eq!(s.set("editor.autosave.onBlur", json!(false)), Ok(true));
for bad in [json!(0), json!("false"), json!(null)] {
assert!(matches!(
s.set("editor.autosave.onTabSwitch", bad),
Err(SetError::Invalid(_))
));
}
assert_eq!(s.set("editor.autosave.idleSeconds", json!(0)), Ok(true));
assert_eq!(s.set("editor.autosave.idleSeconds", json!(600)), Ok(true));
for bad in [json!(-1), json!(601), json!(true)] {
assert!(matches!(
s.set("editor.autosave.idleSeconds", bad),
Err(SetError::Invalid(_))
));
}
}
#[test]
fn every_default_is_valid() {
for d in DEFS {