mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-11 00:11:46 +00:00
PR #12268: a value past the range typed again after text alerts again
CodeRabbit on c36d5ae588: typing 150, then "abc", then 150 again and
leaving the field gave no alert, since the value never changed. The field
now owes the alert again once text that is a number follows text that is
none.
Co-Authored-By: Hector Villarreal <1501713+hectorviov@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c36d5ae588
commit
4772705063
2 files changed
+33
-3
No files matched your search
@@ -86,6 +86,21 @@ fn text_typed_over_a_value_past_the_range_does_not_alert() {
|
||||
assert_eq!(alert(&h), None, "the field is left holding text that is no number: no alert");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_value_past_the_range_typed_again_after_text_alerts() {
|
||||
let mut h = bar();
|
||||
type_without_leaving(&mut h, "150");
|
||||
for text in ["abc", "150"] {
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Text(text.into()));
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
assert_eq!(tolerance(&h), 100.0);
|
||||
assert_eq!(alert(&h).as_deref(), Some(TOLERANCE_RANGE_ALERT), "the field is left holding 150 again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tool_change_while_typing_past_the_range_still_alerts() {
|
||||
let mut h = bar();
|
||||
|
||||
@@ -247,9 +247,23 @@ pub(crate) fn whole_tolerance_field(ui: &mut egui::Ui, value: &mut f32, draft: &
|
||||
}
|
||||
}
|
||||
// Text replaced by something that is no number (`150`, then `abc`) leaves the value alone
|
||||
// when the field is left, with no alert (#12268).
|
||||
if r.has_focus() && widgets::typed_text_parses(ui.ctx(), r.id) == Some(false) {
|
||||
ui.ctx().data_mut(|d| d.remove_temp::<bool>(out_id));
|
||||
// when the field is left, with no alert (#12268). A number typed again after it (`150` once
|
||||
// more) owes the alert again, even though the value did not change.
|
||||
let no_number_id = r.id.with("no-number-typed");
|
||||
if r.has_focus() {
|
||||
match widgets::typed_text_parses(ui.ctx(), r.id) {
|
||||
Some(false) => ui.ctx().data_mut(|d| {
|
||||
d.remove_temp::<bool>(out_id);
|
||||
d.insert_temp(no_number_id, true);
|
||||
}),
|
||||
Some(true) if ui.ctx().data_mut(|d| d.remove_temp::<bool>(no_number_id)).unwrap_or(false) => {
|
||||
let out = typed.is_finite() && !(1.0..=100.0).contains(&typed);
|
||||
ui.ctx().data_mut(|d| d.insert_temp(out_id, out));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
ui.ctx().data_mut(|d| d.remove_temp::<bool>(no_number_id));
|
||||
}
|
||||
if !r.has_focus() {
|
||||
ui.ctx().data_mut(|d| d.remove_temp::<(f32, f32)>(draft_id));
|
||||
@@ -269,6 +283,7 @@ pub(crate) fn whole_tolerance_field(ui: &mut egui::Ui, value: &mut f32, draft: &
|
||||
alert
|
||||
}
|
||||
|
||||
/// Where a whole-number Tolerance field notes the pass in which it last owed the range alert.
|
||||
fn range_alert_owed_id() -> egui::Id {
|
||||
egui::Id::unique("whole-tolerance-range-alert-owed")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user