Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix #250: an area-type frame dragged with the Type tools is the dragged rectangle

theironchefe01077a67452
diff --git a/crates/engine/src/tests_textedit.rs b/crates/engine/src/tests_textedit.rs
index 0462cfd89..2285a1b54 100644
--- a/crates/engine/src/tests_textedit.rs
+++ b/crates/engine/src/tests_textedit.rs
@@ -328,6 +328,23 @@ fn select_all_and_cut_like_ui() {
assert_eq!(obj(&s, id).plain_text(), "abc defabc def");
}
+#[test]
+fn a_frame_dragged_with_the_type_tools_is_the_dragged_rectangle() {
+ for tool in ["type", "verticalType"] {
+ let mut s = session();
+ let v = ViewInfo::default();
+ s.select_tool(tool, v).unwrap();
+ for (k, x, y) in [(PointerKind::Down, 100.0, 100.0), (PointerKind::Drag, 300.0, 180.0), (PointerKind::Up, 300.0, 180.0)] {
+ s.pointer(&PointerEvent::new(k, x, y), v).unwrap();
+ }
+ let t = obj(&s, s.doc().unwrap().selection.objects[0]);
+ let TextKind::Area { frame } = &t.kind else { panic!("{tool}: not area type") };
+ let b = frame.bounds().unwrap();
+ let (a, z) = (t.xf * Point::new(b.x0, b.y0), t.xf * Point::new(b.x1, b.y1));
+ assert!((a - Point::new(100.0, 100.0)).hypot() < 1e-9 && (z - Point::new(300.0, 180.0)).hypot() < 1e-9, "{tool}: {a:?} {z:?}");
+ }
+}
+
#[test]
fn area_type_from_a_circle_keeps_glyphs_inside() {
let mut s = session();
diff --git a/crates/tools/src/text.rs b/crates/tools/src/text.rs
index a152b3882..66523d721 100644
--- a/crates/tools/src/text.rs
+++ b/crates/tools/src/text.rs
@@ -264,7 +264,7 @@ impl TypeTool {
}
let area = drag.map(|d| Rect::from_points(start, d)).filter(|r| r.width() > cx.tol(6.0) && r.height() > cx.tol(6.0));
let mut params = match area {
- Some(r) => json!({"x": r.x0, "y": r.y0 + 12.0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
+ Some(r) => json!({"x": r.x0, "y": r.y0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
None => json!({"x": start.x, "y": start.y, "text": ""}),
};
params["vertical"] = json!(self.vertical);