mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-15 03:37:07 -04:00
Preferences: Story Editor size stays finite and in range (#821)
Preferences OK stored whatever number the dialog held as the Story
Editor font size. One that is not finite ("nan", "inf", or a number
too large for an f32) was written to ui.json as null; the next launch
could not read the file, started with the default UI settings and
saved them over it on exit. The size is now kept between 8 and 36 pt,
the slider's range, and a value that is not a finite number leaves
the size as it was.
This commit is contained in:
1 parent
e862e0a613
commit
ba4519c382
1 file changed
+20
-1
@@ -2009,7 +2009,10 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {
|
||||
let words: Vec<String> = d.s("userWords").lines().map(str::to_string).collect();
|
||||
app.run("spelling.setWords", json!({"words": words}))?;
|
||||
}
|
||||
app.ui.story_editor_size = d.n("storyEditorSize").unwrap_or(14.0) as f32;
|
||||
// The slider's range. A size that isn't finite is saved as `null`, and ui.json then fails to load.
|
||||
if let Some(size) = d.n("storyEditorSize").filter(|v| v.is_finite()) {
|
||||
app.ui.story_editor_size = size.clamp(8.0, 36.0) as f32;
|
||||
}
|
||||
// Highlight options change the screen view only.
|
||||
app.canvas.shown = None;
|
||||
let view = match d.s("displayQuality").as_str() {
|
||||
@@ -4095,6 +4098,22 @@ mod tests {
|
||||
assert!(app.ui.dialog.as_ref().unwrap().b("absolutePageNumbers"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preferences_ok_saves_a_story_editor_size_that_loads_back() {
|
||||
// `ui.dialog.set` takes any value; a size that isn't finite is saved as `null`.
|
||||
let sizes = [(json!("nan"), 20.0), (json!("inf"), 20.0), (json!(null), 20.0), (json!(1e39), 36.0), (json!(3), 8.0), (json!(11), 11.0)];
|
||||
for (size, want) in sizes {
|
||||
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.ui.story_editor_size = 20.0;
|
||||
app.run("app.preferences", json!({})).unwrap();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("storyEditorSize".into(), size);
|
||||
confirm(&mut app).unwrap();
|
||||
let saved = serde_json::to_vec(&app.ui).unwrap();
|
||||
assert_eq!(crate::UiState::from_preferences_json(&saved).unwrap().story_editor_size, want);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_document_vertical_scroll_reaches_last_field() {
|
||||
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
|
||||
Reference in new issue
Block a user