A drawing app built for agent/human collaboration
Rust
Editing a text no longer shows the old words under the new ones
Indicode BV63aa2bba4177
diff --git a/crates/app/src/composite.rs b/crates/app/src/composite.rsindex 49a31d6..4165b40 100644--- a/crates/app/src/composite.rs+++ b/crates/app/src/composite.rs@@ -1496,7 +1496,39 @@ impl Scene {let Some(Loc::Layer(path)) = self.bundle.doc.locate(&layer.id) else {return Err(crate::report::bug(format!("layer {} is not in the scene", layer.id)));};+ let before: BTreeMap<String, Vec<Node>> = self+ .bundle+ .doc+ .layer_at(&path)+ .cels()+ .iter()+ .map(|c| (c.id.clone(), c.nodes.clone()))+ .collect();+ let size = (self.bundle.doc.canvas.width, self.bundle.doc.canvas.height);+ let changed: Vec<(String, Vec<Node>)> = layer+ .cels()+ .iter()+ .filter(|c| self.rasters.contains_key(&c.id))+ .filter(|c| {+ before+ .get(&c.id)+ .is_some_and(|old| nodes_hash(old) != nodes_hash(&c.nodes))+ })+ .map(|c| (c.id.clone(), c.nodes.clone()))+ .collect();*self.bundle.doc.layer_at_mut(&path) = layer;+ let mut dirty = BTreeSet::new();+ changed.into_iter().try_for_each(|(cel, nodes)| {+ let old = before.get(&cel).map(Vec::as_slice).unwrap_or_default();+ let drawn = self+ .rasters+ .get(&cel)+ .filter(|_| self.vector_hash.get(&cel) == Some(&nodes_hash(old)));+ let raster = redraw(&nodes, drawn.map(|r| (old, r)), size)?;+ self.swap_vector(cel.clone(), raster, &mut dirty);+ self.vector_hash.insert(cel, nodes_hash(&nodes));+ Ok::<_, anyhow::Error>(())+ })?;self.rebuild_caches(None)}diff --git a/crates/app/src/editor/ui_tests.rs b/crates/app/src/editor/ui_tests.rsindex aca0b2e..114917d 100644--- a/crates/app/src/editor/ui_tests.rs+++ b/crates/app/src/editor/ui_tests.rs@@ -3129,6 +3129,10 @@ fn text_is_typed_on_the_canvas_and_edited_in_place() {h.key_press(Key::V);h.run_steps(2);assert_eq!(h.state().tool, Tool::Select, "keys work again once typing ends");+ let shapes_cel = h.state().scene.bundle.doc.find_layer("shapes").unwrap().cels()[0]+ .id+ .clone();+ let drawn = h.state().scene.raster_of(&shapes_cel).cloned().unwrap();let on = canvas_at(&h, text.x + 20.0, text.y + text.size * 1.6);h.hover_at(on);h.run_steps(1);@@ -3142,6 +3146,11 @@ fn text_is_typed_on_the_canvas_and_edited_in_place() {h.state().text_edit.as_ref().and_then(|t| t.id.clone()),Some(id.clone()));+ let editing = h.state().scene.raster_of(&shapes_cel).cloned().unwrap();+ assert!(+ !drawn.differs(&editing).is_empty(),+ "the text being edited leaves the layer, so its old words do not show under the typed ones"+ );h.key_press(Key::End);h.event(egui::Event::Text("!".into()));h.run_steps(1);