Expressions: the pick whip inserts at the cursor while editing (#284)
Dragging an expression's pick whip always replaced the whole expression, also while it was being edited (and the editor then wrote its old text back over the reference). As in After Effects, a pick whip pressed while the expression is being edited now puts the reference at the cursor, replacing the selected text, and the editing goes on with the cursor after the reference. Without an edit in progress it replaces the expression as before. `prop.pickWhip` takes the text being edited (`expression`) and the selection in it (`range`, in characters) to insert there. Tests: the_expression_pick_whip_inserts_at_the_cursor_while_editing (ui_inline_edit), pick_whip_inserts_into_the_expression_being_edited (engine). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
02bc2b8f9a
commit
bf09a4fcad
@@ -466,6 +466,33 @@ fn pick_whip_generates_ae_reference_expressions() {
|
||||
assert!(s.execute("prop.pickWhip", json!({"layer": l, "path": "transform/opacity", "target": {"layer": l, "path": "transform/opacity"}})).is_err());
|
||||
}
|
||||
|
||||
/// #284: with the expression being edited, the pick whip puts the reference at the cursor,
|
||||
/// replacing the selected characters (After Effects), in one undo step.
|
||||
#[test]
|
||||
fn pick_whip_inserts_into_the_expression_being_edited() {
|
||||
let (mut s, l) = setup();
|
||||
let o = s.execute("layer.newSolid", json!({"name": "Ö", "color": "#00ff00"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let whip = |s: &mut Session, base: &str, range: Value| {
|
||||
let mut p = json!({"layer": l, "path": "transform/opacity", "target": {"layer": o, "path": "transform/rotation"}, "expression": base});
|
||||
if !range.is_null() {
|
||||
p["range"] = range;
|
||||
}
|
||||
s.execute("prop.pickWhip", p)
|
||||
};
|
||||
let r = "thisComp.layer(\"Ö\").transform.rotation";
|
||||
// Characters, not bytes: "é" before the cursor.
|
||||
assert_eq!(whip(&mut s, "é + 5", json!([1, 1])).unwrap(), json!(format!("é{r} + 5")));
|
||||
assert_eq!(prop(&s, l, "transform/opacity").expr.unwrap().text, format!("é{r} + 5"));
|
||||
// A selection (either way round) is replaced; no range: at the end.
|
||||
assert_eq!(whip(&mut s, "a*2+b", json!([4, 2])).unwrap(), json!(format!("a*{r}b")));
|
||||
assert_eq!(whip(&mut s, "x + ", Value::Null).unwrap(), json!(format!("x + {r}")));
|
||||
// Past the end clamps; a malformed range is an error.
|
||||
assert_eq!(whip(&mut s, "7", json!([9, 99])).unwrap(), json!(format!("7{r}")));
|
||||
assert!(whip(&mut s, "7", json!([1])).is_err());
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(prop(&s, l, "transform/opacity").expr.unwrap().text, format!("x + {r}"));
|
||||
}
|
||||
|
||||
/// Outer comp (4 s) containing a precomp whose 10×10 white solid moves x = 10 + 20·t (t in s).
|
||||
/// Returns (session, precomp layer id in the outer comp).
|
||||
fn precomp_setup() -> (Session, u64) {
|
||||
|
||||
Reference in New Issue
Block a user