diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 90449396b..30c2fdcc6 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -1130,6 +1130,13 @@ impl HostedParamDialog { self.requests.take_help_link() } + /// What the Reset footer restores: the opening values with the dialog's `reset_to` over them. + fn reset_goal(&self) -> DialogFields { + let mut fields = self.fields.clone(); + let reset_to = (self.build)(&mut fields).reset_to; + reset_target(&self.opening, reset_to.as_ref()) + } + /// The answer OK gives with `fields`: the key, the part a remembering dialog saves and this dialog's id, as the /// dialog's own build says them. fn result_of(&mut self, fields: DialogFields) -> ParamResult { @@ -1420,13 +1427,12 @@ impl StackDialog for HostedParamDialog { /// Whether the Reset footer's restore would change the values. fn can_reset(&self) -> bool { - self.fields != self.opening + self.fields != self.reset_goal() } /// Runs the restore the Reset footer runs: the opening values with `reset_to` over them. fn reset(&mut self, _: &Context) -> bool { - let reset_to = (self.build)(&mut self.fields).reset_to; - let target = reset_target(&self.opening, reset_to.as_ref()); + let target = self.reset_goal(); let changed = self.fields != target; self.fields = target; changed diff --git a/crates/ui-patterns/tests/it/form_dialogs/dialog.rs b/crates/ui-patterns/tests/it/form_dialogs/dialog.rs index 1a5ec1493..875113100 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/dialog.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/dialog.rs @@ -1059,7 +1059,7 @@ fn a_run_only_remember_reopens_with_its_values_and_stores_nothing() { } // A host's reset restores the opening values with `reset_to` over them, keeps the dialog open and answers false for an -// unknown id. +// unknown id. Whether it can reset compares with that target: values that opened off it can be reset, and none at it. #[trial] fn a_hosted_dialogs_reset_through_the_host_restores_the_opening_values() { let (host, twice) = (Rc::new(RefCell::new(DialogHost::new())), Rc::new(Cell::new(false))); @@ -1069,12 +1069,13 @@ fn a_hosted_dialogs_reset_through_the_host_restores_the_opening_values() { blur(fields).reset_to(DialogFields::from_pairs([("smooth", true)])) })); fixture.idle(6); - assert!(!host.borrow().can_reset_by_id(id), "nothing changed yet"); + assert!(host.borrow().can_reset_by_id(id), "Smooth opened off its reset target"); host.borrow_mut().set_json_field(&ctx, id, "radius", json!(60.0)).expect("the radius row takes a number"); assert!(host.borrow().can_reset_by_id(id), "an edit can be reset"); assert!(host.borrow_mut().reset_by_id(&ctx, id), "the reset happened"); fixture.idle(4); let fields = on_dialog(&host, |dialog| dialog.fields().clone()).expect("the dialog stays open"); assert_eq!((fields.number("radius"), fields.bool("smooth")), (Some(10.0), Some(true)), "the opening values with reset_to over them"); + assert!(!host.borrow().can_reset_by_id(id), "at the reset target there is nothing to reset"); assert!(!host.borrow_mut().reset_by_id(&ctx, dialog_id("unknown")), "an unknown id answers false"); }