Merge pull request #1054 from pravdomil/claude/shortcuts-keyboard-commands

# Conflicts:
#	crates/engine/src/commands/time.rs
#	crates/ui-egui/src/menus.rs
This commit is contained in:
Brandon Thomas
2026-10-13 04:28:51 -04:00
12 changed files with 727 additions and 9 deletions
+47 -3
View File
@@ -945,6 +945,14 @@ fn timing(s: &mut Session, p: &Value) -> Result<Value> {
let d = t - l.out_point;
shift(l, d);
}
"moveInToStart" => {
let d = Tick::ZERO - l.in_point;
shift(l, d);
}
"moveOutToEnd" => {
let d = comp_dur - l.out_point;
shift(l, d);
}
"trimInToTime" => l.in_point = t.min(l.out_point - fd),
"trimOutToTime" => l.out_point = t.max(l.in_point + fd),
_ => {
@@ -977,6 +985,20 @@ fn timing(s: &mut Session, p: &Value) -> Result<Value> {
Ok(Value::Null)
}
/// `p` with `key` set.
fn with(p: &Value, key: &str, v: Value) -> Value {
let mut p = if p.is_object() { p.clone() } else { json!({}) };
p[key] = v;
p
}
/// Move the layers `frames` frames in time (Alt+Page Up / Page Down, with Shift ten frames).
fn move_frames(s: &mut Session, p: &Value, frames: i64) -> Result<Value> {
let (cid, _) = layers_p(s, p)?;
let delta = s.project.comp(cid).ok_or(EngineError::NoComp)?.frame_rate.tick_of(frames).seconds();
timing(s, &with(p, "delta", json!(delta)))
}
/// Slip edit: move a layer's source (footage or precomp) under its fixed in and out points, like
/// dragging the source-duration bar in After Effects. `delta` in seconds or `frames`; positive
/// moves the source later. Clamped so the source still covers the in–out span. Keyframes and
@@ -1606,6 +1628,16 @@ pub fn specs() -> Vec<CommandSpec> {
cmd!("layer.select", "Select Layers", [], None, "{layers: [id|name|#n], add?, toggle?}", has_comp, select),
cmd!("layer.selectNext", "Select Next Layer", [], Some("Cmd+ArrowDown"), "{add?}", has_comp, select_next),
cmd!("layer.selectPrevious", "Select Previous Layer", [], Some("Cmd+ArrowUp"), "{add?}", has_comp, select_prev),
cmd!("layer.extendSelectionNext", "Extend Selection to Next Layer", [], Some("Cmd+Shift+ArrowDown"), "{}", has_comp, |s, _| select_step(
s,
&json!({"add": true}),
1
)),
cmd!("layer.extendSelectionPrevious", "Extend Selection to Previous Layer", [], Some("Cmd+Shift+ArrowUp"), "{}", has_comp, |s, _| select_step(
s,
&json!({"add": true}),
-1
)),
cmd!(
"layer.setSwitch",
"Layer Switch",
@@ -1633,17 +1665,29 @@ pub fn specs() -> Vec<CommandSpec> {
"Layer Timing",
[],
None,
"{layers?, op?: moveInToTime|moveOutToTime|trimInToTime|trimOutToTime, delta?, start?, in?, out?, inDelta?, outDelta? (seconds, per layer), merge?}",
"{layers?, op?: moveInToTime|moveOutToTime|moveInToStart|moveOutToEnd|trimInToTime|trimOutToTime, delta?, start?, in?, out?, inDelta?, outDelta? (seconds, per layer), merge?}",
has_layers,
timing
),
cmd!("layer.moveInToStart", "Move Layer In Point to Beginning of Comp", [], Some("Alt+Home"), "{layers?}", has_layers, |s, p| timing(
s,
&with(p, "op", json!("moveInToStart"))
)),
cmd!("layer.moveOutToEnd", "Move Layer Out Point to End of Comp", [], Some("Alt+End"), "{layers?}", has_layers, |s, p| timing(
s,
&with(p, "op", json!("moveOutToEnd"))
)),
cmd!("layer.moveEarlier", "Move Layers 1 Frame Earlier", [], Some("Alt+PageUp"), "{layers?}", has_layers, |s, p| move_frames(s, p, -1)),
cmd!("layer.moveLater", "Move Layers 1 Frame Later", [], Some("Alt+PageDown"), "{layers?}", has_layers, |s, p| move_frames(s, p, 1)),
cmd!("layer.moveEarlier10", "Move Layers 10 Frames Earlier", [], Some("Alt+Shift+PageUp"), "{layers?}", has_layers, |s, p| move_frames(s, p, -10)),
cmd!("layer.moveLater10", "Move Layers 10 Frames Later", [], Some("Alt+Shift+PageDown"), "{layers?}", has_layers, |s, p| move_frames(s, p, 10)),
cmd!("layer.slip", "Slip Edit", [], None, "{layers?, delta? (seconds) | frames?, merge?}", has_layers, slip),
cmd!("layer.slipBack", "Slip Edit 1 Frame Earlier", [], Some("Alt+PageUp"), "{layers?}", has_layers, |s, p| {
cmd!("layer.slipBack", "Slip Edit 1 Frame Earlier", [], None, "{layers?}", has_layers, |s, p| {
let mut p = p.clone();
p["frames"] = json!(-1);
slip(s, &p)
}),
cmd!("layer.slipForward", "Slip Edit 1 Frame Later", [], Some("Alt+PageDown"), "{layers?}", has_layers, |s, p| {
cmd!("layer.slipForward", "Slip Edit 1 Frame Later", [], None, "{layers?}", has_layers, |s, p| {
let mut p = p.clone();
p["frames"] = json!(1);
slip(s, &p)
+26 -1
View File
@@ -24,6 +24,11 @@ fn time_stretch(s: &mut Session, p: &Value) -> Result<Value> {
let pct = f_p(p, "percent");
let dur = f_p(p, "duration");
let hold = str_p(p, "hold").unwrap_or("in").to_string();
// `to`: stretch so the In (or Out) point lands on the current time, the other point held.
let to = str_p(p, "to").map(str::to_string);
if to.as_deref().is_some_and(|t| t != "in" && t != "out") {
return Err(bad("layer.timeStretch", "to: in|out"));
}
let cti = s.time();
let comp_rate = s.project.comp(cid).ok_or(EngineError::NoComp)?.frame_rate;
let fd = comp_rate.frame_duration();
@@ -39,6 +44,16 @@ fn time_stretch(s: &mut Session, p: &Value) -> Result<Value> {
continue;
}
let span = (l.out_point - l.in_point).seconds();
let (dur, hold) = match to.as_deref() {
Some("in") => (Some((l.out_point - cti).seconds()), "out"),
Some(_) => (Some((cti - l.in_point).seconds()), "in"),
None => (dur, hold.as_str()),
};
// The current time is on the wrong side of the held point: nothing to stretch to.
if to.is_some() && dur.is_some_and(|d| d < fd.seconds()) {
continue;
}
let pct = if to.is_some() { None } else { pct };
let new = match (pct, dur) {
(Some(v), _) => v,
(None, Some(d)) if span > 0.0 => old * d / span,
@@ -48,7 +63,7 @@ fn time_stretch(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad("layer.timeStretch", "the stretch factor must be at least 1 %"));
}
// The hold point keeps showing the same layer time.
let h = match hold.as_str() {
let h = match hold {
"current" => cti,
"out" => l.out_point,
_ => l.in_point,
@@ -220,6 +235,16 @@ pub fn specs() -> Vec<CommandSpec> {
has_layers,
time_stretch
),
cmd!("layer.stretchInToTime", "Stretch Layer In Point to Current Time", [], Some("Cmd+Shift+,"), "{layers?}", has_layers, |s, p| {
let mut p = if p.is_object() { p.clone() } else { json!({}) };
p["to"] = json!("in");
time_stretch(s, &p)
}),
cmd!("layer.stretchOutToTime", "Stretch Layer Out Point to Current Time", [], Some("Cmd+Alt+,"), "{layers?}", has_layers, |s, p| {
let mut p = if p.is_object() { p.clone() } else { json!({}) };
p["to"] = json!("out");
time_stretch(s, &p)
}),
cmd!("layer.timeReverse", "Time-Reverse Layer", ["Layer", "Time"], Some("Cmd+Alt+R"), "{layers?}", has_layers, |s, p| {
let mut p = p.clone();
p["op"] = json!("reverse");
+2
View File
@@ -39,6 +39,7 @@ pub mod markers;
mod mask;
pub mod mask_interp;
pub(crate) mod model3d;
mod nav_more;
pub mod paint;
pub mod panels_cmds;
pub(crate) mod path_nulls;
@@ -176,6 +177,7 @@ pub fn command_specs() -> &'static [CommandSpec] {
v.extend(paths::specs());
v.extend(effect::specs());
v.extend(time::specs());
v.extend(nav_more::specs());
v.extend(render_queue::specs());
v.extend(help::specs());
v.extend(query::specs());
+147
View File
@@ -0,0 +1,147 @@
//! Keyboard-driven commands that have no menu entry.
use std::collections::BTreeSet;
use effectcraft_keyframe::Value as KV;
use effectcraft_project::{ItemId, LayerSource, Project};
use effectcraft_time::Tick;
use serde_json::{Value, json};
use super::{CommandSpec, always, bad, comp_id, has_comp, has_layers, layers_p};
use crate::{EngineError, Result, Session, cmd};
/// Ctrl+Alt+B: the work area spans the selected layers (their earliest In to their latest Out
/// point), or the whole composition with none selected.
fn work_area_to_selection(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, ids) = layers_p(s, p)?;
s.edit("Work Area", None, |proj, _| {
let c = proj.comp_mut(cid).ok_or(EngineError::NoComp)?;
let fd = c.frame_duration();
let spans: Vec<(Tick, Tick)> = c.layers.iter().filter(|l| ids.contains(&l.id)).map(|l| (l.in_point, l.out_point)).collect();
let (start, end) = match (spans.iter().map(|s| s.0).min(), spans.iter().map(|s| s.1).max()) {
(Some(a), Some(b)) => (a, b),
_ => (Tick::ZERO, c.duration),
};
// min/max, not clamp: the bounds cross on a comp shorter than a frame.
let start = start.min(c.duration - fd).max(Tick::ZERO);
c.work_area = (start, end.min(c.duration).max(start + fd));
Ok(())
})?;
let c = s.project.comp(cid).ok_or(EngineError::NoComp)?;
Ok(json!({"start": c.work_area.0.seconds(), "end": c.work_area.1.seconds()}))
}
/// Shift+F2: no keyframe, property or property group is selected; the layers stay selected.
fn deselect_keys(s: &mut Session, _: &Value) -> Result<Value> {
s.state.selected_keys.clear();
s.state.selected_props.clear();
s.state.selected_vertices.clear();
Ok(Value::Null)
}
/// Alt+` / Alt+Shift+`: select the next (previous) mask of the layer, wrapping around; the first
/// (last) one when none is selected.
fn step_mask(s: &mut Session, p: &Value, dir: i64) -> Result<Value> {
let cmd = if dir > 0 { "layer.mask.selectNext" } else { "layer.mask.selectPrevious" };
let (cid, ids) = layers_p(s, p)?;
let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?;
let (lid, masks) = ids
.iter()
.filter_map(|id| comp.layer(*id))
.find_map(|l| l.masks().filter(|m| m.groups().next().is_some()).map(|m| (l.id, m)))
.ok_or_else(|| bad(cmd, "the selected layers have no masks"))?;
let groups: Vec<_> = masks.groups().collect();
let n = groups.len() as i64;
// The selected mask: its group, or a property inside it.
let selected = |g: &effectcraft_project::PropGroup| {
s.state.selected_props.iter().any(|(l, uid)| *l == lid && (g.find_group(*uid).is_some() || g.find(*uid).is_some()))
};
let i = match groups.iter().position(|g| selected(g)) {
Some(i) => (i as i64 + dir).rem_euclid(n.max(1)),
None if dir > 0 => 0,
None => n - 1,
};
let uid = groups.get(i as usize).map(|g| g.uid).ok_or_else(|| bad(cmd, "the selected layers have no masks"))?;
s.state.selected_props = vec![(lid, uid)];
s.state.selected_keys.clear();
s.state.selected_vertices.clear();
Ok(json!({"layer": lid.0, "mask": uid, "index": i + 1}))
}
/// Alt+Shift+C: Casts Shadows on or off for the selected 3D layers (all follow the first one).
fn casts_shadows(s: &mut Session, p: &Value) -> Result<Value> {
const PATH: &str = "materialOptions/castsShadows";
let (cid, ids) = layers_p(s, p)?;
let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?;
let with: Vec<_> = ids.iter().filter_map(|id| comp.layer(*id)).filter(|l| l.switches.three_d && l.props.prop(PATH).is_some()).collect();
let first = with.first().ok_or_else(|| bad("layer.castsShadows", "select a 3D layer"))?;
let on = match p.get("value").and_then(Value::as_bool) {
Some(v) => v,
None => first.props.prop(PATH).is_none_or(|pr| pr.value == KV::Enum(0)),
};
let layers: Vec<u64> = with.iter().map(|l| l.id.0).collect();
let set = super::find("material.set").ok_or_else(|| bad("layer.castsShadows", "Material Options are not available"))?;
(set.run)(s, &json!({"comp": cid.0, "layers": layers, "castsShadows": if on { "on" } else { "off" }}))?;
Ok(json!({"castsShadows": on, "layers": layers}))
}
/// The comps connected to `from` by nesting, in either direction (its network of nested
/// compositions), `from` included.
fn hierarchy(proj: &Project, from: ItemId) -> BTreeSet<ItemId> {
let mut edges: Vec<(ItemId, ItemId)> = Vec::new();
for item in proj.items.values() {
let Some(c) = item.as_comp() else { continue };
for l in &c.layers {
if let LayerSource::Comp { item: nested } = &l.source {
edges.push((item.id, *nested));
}
}
}
let mut seen = BTreeSet::from([from]);
let mut todo = vec![from];
while let Some(c) = todo.pop() {
for (a, b) in &edges {
let other = if *a == c {
*b
} else if *b == c {
*a
} else {
continue;
};
if seen.insert(other) {
todo.push(other);
}
}
}
seen
}
/// Shift+Esc: activate the composition that was active most recently among those in the active
/// composition's nesting hierarchy.
fn activate_recent(s: &mut Session, p: &Value) -> Result<Value> {
let cid = comp_id(s, p)?;
let related = hierarchy(&s.project, cid);
let next = s.state.recent_comps.iter().copied().find(|c| *c != cid && related.contains(c) && s.project.comp(*c).is_some());
let Some(next) = next else { return Ok(Value::Null) };
s.open_comp(next);
Ok(json!({"comp": next.0}))
}
pub fn specs() -> Vec<CommandSpec> {
vec![
cmd!(
"comp.workAreaToSelection",
"Set Work Area to Selected Layers",
[],
Some("Cmd+Alt+B"),
"{comp?, layers? (default the selected layers; the whole composition with none)}",
has_comp,
work_area_to_selection
),
cmd!("comp.activateRecent", "Activate Most Recent Composition in Hierarchy", [], Some("Shift+Escape"), "{comp?}", has_comp, activate_recent),
cmd!("keys.deselectAll", "Deselect All Keyframes and Properties", [], ["Shift+F2", "Cmd+Alt+Shift+A"], "{}", always, deselect_keys),
cmd!("layer.mask.selectNext", "Select Next Mask", [], Some("Alt+`"), "{layer?}", has_layers, |s, p| step_mask(s, p, 1)),
cmd!("layer.mask.selectPrevious", "Select Previous Mask", [], Some("Alt+Shift+`"), "{layer?}", has_layers, |s, p| step_mask(s, p, -1)),
cmd!("layer.castsShadows", "Casts Shadows", [], Some("Alt+Shift+C"), "{layers?, value?}", has_layers, casts_shadows),
]
}
+17 -2
View File
@@ -100,6 +100,14 @@ fn go(s: &mut Session, p: &Value) -> Result<Value> {
"workEnd" => comp.work_area.1 - comp.frame_duration(),
"layerIn" => sel_layer.map(|l| l.in_point).unwrap_or(t),
"layerOut" => sel_layer.map(|l| l.out_point - comp.frame_duration()).unwrap_or(t),
"nextInOut" | "prevInOut" => {
// In and Out points (its last frame) of the selected layers, of every layer with none
// selected.
let sel = &s.state.selected_layers;
let times =
comp.layers.iter().filter(|l| sel.is_empty() || sel.contains(&l.id)).flat_map(|l| [l.in_point, l.out_point - comp.frame_duration()]).collect();
step_to(times, t, comp.frame_duration(), to == "nextInOut")
}
"nextKey" | "prevKey" if visible.is_some() => {
// What the Timeline shows: keys of its revealed properties, layer and comp markers
// and the work area (After Effects' "visible items").
@@ -148,7 +156,7 @@ fn go(s: &mut Session, p: &Value) -> Result<Value> {
}
step_to(times, t, comp.frame_duration(), to == "nextKey")
}
_ => return Err(super::bad("time.go", "to: start|end|workStart|workEnd|layerIn|layerOut|nextKey|prevKey")),
_ => return Err(super::bad("time.go", "to: start|end|workStart|workEnd|layerIn|layerOut|nextInOut|prevInOut|nextKey|prevKey")),
};
s.set_time(target);
Ok(report(s))
@@ -180,6 +188,13 @@ pub fn specs() -> Vec<CommandSpec> {
cmd!("time.step", "Step Frames", [], None, "{frames}", has_comp, step),
cmd!("time.start", "Go to Start", [], ["Home", "Cmd+Alt+ArrowLeft"], "{}", has_comp, |s, _| go(s, &json!({"to": "start"}))),
cmd!("time.end", "Go to End", [], ["End", "Cmd+Alt+ArrowRight"], "{}", has_comp, |s, _| go(s, &json!({"to": "end"}))),
cmd!("time.workAreaStart", "Go to Work Area Start", [], Some("Shift+Home"), "{}", has_comp, |s, _| go(s, &json!({"to": "workStart"}))),
cmd!("time.workAreaEnd", "Go to Work Area End", [], Some("Shift+End"), "{}", has_comp, |s, _| go(s, &json!({"to": "workEnd"}))),
cmd!("time.previousInOut", "Go to Previous In or Out Point", [], Some("Cmd+Alt+Shift+ArrowLeft"), "{}", has_comp, |s, _| go(
s,
&json!({"to": "prevInOut"})
)),
cmd!("time.nextInOut", "Go to Next In or Out Point", [], Some("Cmd+Alt+Shift+ArrowRight"), "{}", has_comp, |s, _| go(s, &json!({"to": "nextInOut"}))),
cmd!("time.layerIn", "Go to Layer In Point", [], Some("I"), "{}", has_comp, |s, _| go(s, &json!({"to": "layerIn"}))),
cmd!("time.layerOut", "Go to Layer Out Point", [], Some("O"), "{}", has_comp, |s, _| go(s, &json!({"to": "layerOut"}))),
cmd!(
@@ -200,7 +215,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Go To",
[],
None,
"{to: start|end|workStart|workEnd|layerIn|layerOut|nextKey|prevKey, prop?: uid, visible?: [{layer, prop}]}",
"{to: start|end|workStart|workEnd|layerIn|layerOut|nextInOut|prevInOut|nextKey|prevKey, prop?: uid, visible?: [{layer, prop}]}",
has_comp,
go
),