M12: an exit skipped after a value change is skipped only until the next edit, undo or redo

This commit is contained in:
Eric Kaden committed 2026-10-23 23:36:15 -04:00
1 parent 7e00c61c7f
commit 2e8720c332
2 files changed
+29

No files matched your search

+7
View File
@@ -4012,6 +4012,9 @@ impl Session {
doc.dirty = true;
doc.generation += 1;
doc.edit_notices = notices;
// Only this edit's exits are skipped on the next focus loss: one an earlier change ran is
// no reason to skip a later one.
doc.xfa_exited.clear();
doc.xfa_exited.extend(exited);
if !cx.xfa_removed.is_empty() {
let removed: Vec<String> = cx.xfa_removed.iter().map(|n| format!("{XFA_REMOVED_PREFIX}{n}")).collect();
@@ -4059,6 +4062,8 @@ impl Session {
}
doc.edit_notices.clear();
Self::sync_dirty(doc);
// The change whose exit ran is undone (or redone without its scripts): skip no exit.
doc.xfa_exited.clear();
doc.generation += 1;
Ok(label)
}
@@ -4088,6 +4093,8 @@ impl Session {
}
doc.edit_notices.clear();
Self::sync_dirty(doc);
// The change whose exit ran is undone (or redone without its scripts): skip no exit.
doc.xfa_exited.clear();
doc.generation += 1;
Ok(label)
}
+22
View File
@@ -4719,6 +4719,28 @@ fn an_exit_the_fields_change_ran_does_not_run_twice() {
assert_eq!(field_text(&s, id, "exits"), "2", "the next visit's exit runs");
}
/// The skip lasts only until the next edit, undo or redo: a change that is undone, or followed by
/// another edit, doesn't make a later focus loss skip the field's exit.
#[test]
fn an_exit_skip_does_not_outlive_its_change() {
use crate::js::FieldFocus::{Enter, Exit};
let mut s = Session::new();
let id = s.open("form.pdf", None, focus_form(), None).expect("opens");
s.field_focus(id, "probe", 0, Enter).unwrap();
s.apply(id, Edit::SetFieldValue { name: "probe".into(), value: FieldValue::Text("x".into()) }).unwrap();
s.undo(id).unwrap();
let before = field_text(&s, id, "exits");
s.field_focus(id, "probe", 0, Exit).unwrap();
assert_eq!(field_text(&s, id, "exits"), (before.parse::<u32>().unwrap() + 1).to_string(), "after an undo, the exit runs");
// A change, then an edit of another field: the change's skip is gone.
s.field_focus(id, "probe", 0, Enter).unwrap();
s.apply(id, Edit::SetFieldValue { name: "probe".into(), value: FieldValue::Text("y".into()) }).unwrap();
s.apply(id, Edit::SetFieldValue { name: "quiet".into(), value: FieldValue::Text("z".into()) }).unwrap();
let before = field_text(&s, id, "exits");
s.field_focus(id, "probe", 0, Exit).unwrap();
assert_eq!(field_text(&s, id, "exits"), (before.parse::<u32>().unwrap() + 1).to_string(), "after another edit, the exit runs");
}
/// Scripts that change nothing leave no edit: the document stays saved, with nothing to undo,
/// and what they showed still reaches the viewer. A field without such scripts runs nothing.
#[test]