diff --git a/crates/engine/src/link_watch.rs b/crates/engine/src/link_watch.rs index c30f8b58..8d9df187 100644 --- a/crates/engine/src/link_watch.rs +++ b/crates/engine/src/link_watch.rs @@ -97,6 +97,11 @@ impl Session { if self.active().map(|d| d.uid) != Some(uid) { return Ok(none()); } + // A drag is in progress: its next preview or cancel would throw an update away while the new + // stamp stayed recorded. Leave the stamps alone; the first look after the drag sees the change. + if self.in_interaction() { + return Ok(none()); + } // This document's last stamps; those of closed documents are dropped. let open: HashSet = self.documents().iter().map(|d| d.uid).collect(); let mut before: HashMap = HashMap::new(); diff --git a/crates/engine/src/tests_linkwatch.rs b/crates/engine/src/tests_linkwatch.rs index 6d2d0b87..26b9252d 100644 --- a/crates/engine/src/tests_linkwatch.rs +++ b/crates/engine/src/tests_linkwatch.rs @@ -86,3 +86,21 @@ fn a_file_still_being_written_is_tried_again() { assert_eq!(look(&mut s)["updated"], json!([id.0])); assert_eq!(colour(&s), BLUE); } + +#[test] +fn a_change_during_a_drag_waits_for_the_drag_to_end() { + let dir = Folder::new("watch-drag"); + let path = dir.file("art.png"); + std::fs::write(&path, png(40, 40, RED)).unwrap(); + let mut s = session(); + s.prefs.update_links = "automatically".into(); + let id = place(&mut s, &path); + look(&mut s); + s.begin_interaction("Move").unwrap(); + save(&path, &png(40, 40, BLUE)); + // The preview would throw the update away, so it is not applied (nor its stamp kept). + assert_eq!(look(&mut s), json!({"updated": [], "ask": [], "modified": []})); + s.cancel_interaction().unwrap(); + assert_eq!(look(&mut s)["updated"], json!([id.0])); + assert_eq!(colour(&s), BLUE); +}