Timeline: box selection selects keyframes live while it's dragged (#2858) (#2952)

* Timeline: box selection selects keyframes live while it is dragged (#2858)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Timeline: a Cmd/Ctrl box over keys alone adds to the selection, as Shift does (#2858)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Timeline: a box over keys alone clears the earlier selection first, as main's box does (#2858)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #2858: marquee keeps its live selection in the UI and commits through commands

While a Timeline box is dragged, what it would select is a UI-side preview
(`TimelineState::marquee_preview`) that the rows draw as the selection; the
engine's selection is not written. The release runs main's `layer.select` and
`keys.select`, and Escape or any other end just drops the preview, so the
direct `Before::restore` writes are gone and the command journal replays to
the live selection (AGENTS.md rule 14).

Tests replay the journal on a fresh session after a Shift box that grows and
shrinks, and after a box cancelled with Escape; both fail on the previous
commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bar Borer
2026-12-01 11:51:45 +02:00
committed by GitHub
parent 3e98b2377c
commit 672f776f99
4 changed files with 356 additions and 12 deletions
+6 -3
View File
@@ -1750,8 +1750,10 @@ struct Rw {
empty_rect: Rect,
empty: egui::Response,
outline_empty: egui::Response,
/// The selection the rows show: the engine's, or a box's preview while one is dragged.
selected: Vec<LayerId>,
sel_keys: Vec<effectcraft_engine::KeyRef>,
sel_props: Vec<(LayerId, u64)>,
ui_actions: Vec<UiAct>,
hit_rows: Vec<(Rect, Row)>,
dim_hits: Vec<(u64, Vec<Rect>)>,
@@ -1959,6 +1961,7 @@ fn begin_rows(app: &mut EffectcraftApp, ui: &mut egui::Ui, tl: Tl) -> Rw {
outline_empty,
selected: app.session.state.selected_layers.clone(),
sel_keys: app.session.state.selected_keys.clone(),
sel_props: app.session.state.selected_props.clone(),
ui_actions: Vec::new(),
hit_rows: Vec::new(),
dim_hits: Vec::new(),
@@ -3616,7 +3619,7 @@ fn group_background(app: &mut EffectcraftApp, g: &Rw, rc: &RowCtx<'_>) -> String
};
// Selected groups (an effect, a mask, a shape group…) highlight like selected
// property rows.
let sel_group = app.session.state.selected_props.contains(&(layer.id, *uid));
let sel_group = g.sel_props.contains(&(layer.id, *uid));
lp.rect_filled(
left,
0.0,
@@ -3937,7 +3940,7 @@ fn expr_controls(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &R
let cy = rc.cy;
let ri = rc.ri;
let RowKind::Expr { uid, .. } = &rc.row.kind else { return };
let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
let sel_prop = g.sel_props.contains(&(layer.id, *uid));
lp.rect_filled(
left,
0.0,
@@ -4133,7 +4136,7 @@ fn prop_background(app: &mut EffectcraftApp, g: &Rw, rc: &RowCtx<'_>, prop: &Pro
let uid = &prop.uid;
app.auto.add(&format!("timeline.prop.{uid}.row"), r, &prop.name);
let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
let sel_prop = g.sel_props.contains(&(layer.id, *uid));
lp.rect_filled(
left,
0.0,
+60 -8
View File
@@ -6,8 +6,12 @@ use effectcraft_engine::project::Comp;
use egui::{Id, Pos2, Rect, Stroke, StrokeKind, pos2};
use serde_json::json;
use effectcraft_engine::KeyRef;
use effectcraft_engine::project::LayerId;
use super::{Row, RowKind, Rw, TMap, edge_scroll_speed, keys_in_box, row_height};
use crate::EffectcraftApp;
use crate::state::SelectionPreview;
#[derive(Clone)]
struct Marquee {
@@ -48,9 +52,11 @@ fn id() -> Id {
Id::unique("tl-marquee")
}
/// Capture on press, before wheel handling, even if the drag threshold is not crossed yet.
pub(super) fn prepare(app: &EffectcraftApp, ui: &egui::Ui, g: &Rw) {
let ctx = &g.tl.ctx;
/// Capture on press, before wheel handling, even if the drag threshold is not crossed yet. While a
/// box is dragged the rows show its preview (#2858); a box that ends any way but its release
/// (Escape, losing the pointer, the comp or rows changing) drops the preview and selects nothing.
pub(super) fn prepare(app: &mut EffectcraftApp, ui: &egui::Ui, g: &mut Rw) {
let ctx = g.tl.ctx.clone();
let (pressed, down, released, escape, focused) =
ctx.input(|i| (i.pointer.primary_pressed(), i.pointer.primary_down(), i.pointer.primary_released(), i.key_pressed(egui::Key::Escape), i.focused));
if let Some(mut drag) = ctx.data(|d| d.get_temp::<Marquee>(id())) {
@@ -73,6 +79,13 @@ pub(super) fn prepare(app: &EffectcraftApp, ui: &egui::Ui, g: &Rw) {
}
});
}
if ctx.data(|d| d.get_temp::<Marquee>(id())).is_none() {
app.ui.timeline.marquee_preview = None;
} else if let Some(p) = &app.ui.timeline.marquee_preview {
g.selected.clone_from(&p.layers);
g.sel_keys.clone_from(&p.keys);
g.sel_props.clone_from(&p.props);
}
if pressed && ui.is_enabled() && focused && !escape {
let owner = [&g.outline_empty, &g.empty].into_iter().find(|r| r.is_pointer_button_down_on());
if let Some(owner) = owner
@@ -163,9 +176,10 @@ pub(super) fn targets(
(layers, keys_in_box(comp, rows, tm, top, rh, selection.keys))
}
/// Commit an owned primary release; otherwise paint without changing selection.
pub(super) fn finish(app: &EffectcraftApp, ui: &egui::Ui, g: &mut Rw) {
let ctx = &g.tl.ctx;
/// Preview what the box touches as it is dragged (#2858) and paint it; the release selects it
/// through the selection commands, so automation and replays see one selection, not each frame's.
pub(super) fn finish(app: &mut EffectcraftApp, ui: &egui::Ui, g: &mut Rw) {
let ctx = g.tl.ctx.clone();
let Some(drag) = ctx.data(|d| d.get_temp::<Marquee>(id())) else { return };
let released = ctx.input(|i| i.pointer.primary_released());
let dropped = released && ctx.drag_stopped_id() == Some(drag.owner);
@@ -174,19 +188,57 @@ pub(super) fn finish(app: &EffectcraftApp, ui: &egui::Ui, g: &mut Rw) {
}
let Some(pointer) = ctx.input(|i| i.pointer.latest_pos()) else { return };
let (paint, selection) = drag.anchor.selection(&View::of(g), app.ui.timeline.scroll_y, pointer);
let (layers, keys) = targets(&g.tl.comp, &g.tl.rows, &g.tl.tm, g.tl.rows_rect.min.y - app.ui.timeline.scroll_y, g.tl.rh, paint, &selection);
let add = ui.input(|i| i.modifiers.shift || i.modifiers.command);
if dropped {
ctx.data_mut(|d| d.remove::<Marquee>(id()));
let (layers, keys) = targets(&g.tl.comp, &g.tl.rows, &g.tl.tm, g.tl.rows_rect.min.y - app.ui.timeline.scroll_y, g.tl.rh, paint, &selection);
let add = ui.input(|i| i.modifiers.shift || i.modifiers.command);
app.ui.timeline.marquee_preview = None;
// A box that catches nothing leaves nothing selected (layers included), unless it adds.
g.tl.actions.push(("layer.select".into(), json!({"layers": layers, "add": add})));
if !keys.is_empty() {
let keys: Vec<_> = keys.iter().map(|k| json!({"layer": k.layer.0, "prop": k.prop, "time": k.time.seconds()})).collect();
g.tl.actions.push(("keys.select".into(), json!({"keys": keys, "add": true, "selectProperties": true})));
}
} else {
let shown = Some(preview(&app.session.state, &g.tl.comp, &layers, &keys, add));
if app.ui.timeline.marquee_preview != shown {
app.ui.timeline.marquee_preview = shown;
ctx.request_repaint();
}
let clip = if selection.outline { g.tl.rows_rect } else { g.right_clip };
let painter = g.tl.p.with_clip_rect(clip);
painter.rect_filled(paint, 0.0, g.tl.t.accent.gamma_multiply(0.12));
painter.rect_stroke(paint, 0.0, Stroke::new(1.0, g.tl.t.accent), StrokeKind::Inside);
}
}
/// The selection the release's commands would leave, for the rows to show while the box moves:
/// `layer.select` (adding with Shift or Cmd/Ctrl, else replacing the layers and dropping the
/// properties and keys), then, when the box holds keys, `keys.select` adding the unlocked ones
/// with their properties and layers.
fn preview(st: &effectcraft_engine::EditorState, comp: &Comp, layers: &[u64], keys: &[KeyRef], add: bool) -> SelectionPreview {
fn push<T: PartialEq>(v: &mut Vec<T>, x: T) {
if !v.contains(&x) {
v.push(x);
}
}
let boxed = layers.iter().map(|l| LayerId(*l)).filter(|l| comp.layer(*l).is_some());
let mut p = if add {
SelectionPreview { layers: st.selected_layers.clone(), props: st.selected_props.clone(), keys: st.selected_keys.clone() }
} else {
SelectionPreview::default()
};
for l in boxed {
push(&mut p.layers, l);
}
if !keys.is_empty() {
for k in keys.iter().filter(|k| comp.layer(k.layer).is_some_and(|l| !l.switches.locked)) {
push(&mut p.keys, *k);
}
for k in p.keys.clone() {
push(&mut p.props, (k.layer, k.prop));
push(&mut p.layers, k.layer);
}
}
p
}
+15
View File
@@ -515,6 +515,20 @@ pub struct TimelineState {
/// A pending scroll, applied when the Timeline is next drawn.
#[serde(skip)]
pub scroll_to: Option<ScrollTo>,
/// What a box being dragged in the Timeline would select (#2858). The rows show it as
/// selected while the box moves; the release commits it through the selection commands and
/// Escape drops it, so the engine's selection changes only through commands.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub marquee_preview: Option<SelectionPreview>,
}
/// A selection shown in the Timeline but not yet made: layers, properties and keys, as the
/// selection commands would leave them.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct SelectionPreview {
pub layers: Vec<effectcraft_engine::project::LayerId>,
pub props: Vec<(effectcraft_engine::project::LayerId, u64)>,
pub keys: Vec<effectcraft_engine::KeyRef>,
}
pub fn default_tl_columns() -> BTreeSet<String> {
@@ -561,6 +575,7 @@ impl Default for TimelineState {
columns: default_tl_columns(),
source_name: false,
scroll_to: None,
marquee_preview: None,
}
}
}
+275 -1
View File
@@ -1,5 +1,6 @@
//! The key marquee in the Timeline (#2857): a box selects a key as soon as it touches any part of
//! the key's glyph, not when it reaches the key's center.
//! the key's glyph, not when it reaches the key's center. The rows show what it selects as it
//! moves, and the release selects that through the selection commands (#2858).
use effectcraft_engine::Session;
use effectcraft_engine::project::LayerId;
@@ -82,6 +83,278 @@ fn a_box_selects_a_key_it_grazes_from_any_side_and_not_one_it_stops_short_of() {
}
}
/// Press at `from` with `modifiers` held, ready to drag.
fn press_with(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, modifiers: Modifiers) {
h.event(Event::ModifiersChanged(modifiers));
h.input_mut().events.push(Event::PointerMoved(from));
h.step();
h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers });
h.step();
}
/// Drag the pointer to `to` in a straight line from `from` (the button stays down).
fn drag(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) {
for i in 1..=8 {
h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (i as f32 / 8.0)));
h.step();
}
}
fn release_with(h: &mut Harness<'_, EffectcraftApp>, at: Pos2, modifiers: Modifiers) {
h.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers });
h.step();
h.event(Event::ModifiersChanged(Modifiers::NONE));
h.run_steps(2);
}
/// The keys the rows show as selected (seconds): the box's preview while one is dragged, else
/// the engine's selection.
fn selected(h: &Harness<'_, EffectcraftApp>) -> Vec<f64> {
let st = h.state();
let keys = st.ui.timeline.marquee_preview.as_ref().map_or(&st.session.state.selected_keys, |p| &p.keys);
let mut times: Vec<f64> = keys.iter().map(|k| k.time.seconds()).collect();
times.sort_by(f64::total_cmp);
times
}
/// The layers the rows show as selected, as [`selected`] does keys.
fn shown_layers(h: &Harness<'_, EffectcraftApp>) -> Vec<LayerId> {
let st = h.state();
st.ui.timeline.marquee_preview.as_ref().map_or(&st.session.state.selected_layers, |p| &p.layers).clone()
}
/// A selection (layers, properties, keys, mask vertices) in a comparable order.
type Selection = (Vec<u64>, Vec<(u64, u64)>, Vec<(u64, u64, i64)>, Vec<(u64, u64, usize)>);
fn selection(st: &effectcraft_engine::EditorState) -> Selection {
let mut s = (
st.selected_layers.iter().map(|l| l.0).collect::<Vec<_>>(),
st.selected_props.iter().map(|(l, p)| (l.0, *p)).collect::<Vec<_>>(),
st.selected_keys.iter().map(|k| (k.layer.0, k.prop, k.time.0)).collect::<Vec<_>>(),
st.selected_vertices.iter().map(|v| (v.layer.0, v.mask, v.index)).collect::<Vec<_>>(),
);
s.0.sort_unstable();
s.1.sort_unstable();
s.2.sort_unstable();
s.3.sort_unstable();
s
}
/// The preview the rows show, in [`selection`]'s order (it has no mask vertices).
fn preview(h: &Harness<'_, EffectcraftApp>) -> Option<Selection> {
let p = h.state().ui.timeline.marquee_preview.as_ref()?;
let mut st = effectcraft_engine::EditorState::default();
st.selected_layers.clone_from(&p.layers);
st.selected_props.clone_from(&p.props);
st.selected_keys.clone_from(&p.keys);
Some(selection(&st))
}
/// Replay the live session's command journal on a fresh document and return its selection, as an
/// agent that recorded the session would get it back.
fn replayed(h: &Harness<'_, EffectcraftApp>) -> Selection {
let mut fresh = Session::default();
for (cmd, params) in &h.state().session.journal {
fresh.execute(cmd, params.clone()).unwrap_or_else(|e| panic!("replaying {cmd} {params}: {e}"));
}
selection(&fresh.state)
}
/// Select the key at `secs` as a click on it does: its property and layer too.
fn select_key(h: &mut Harness<'_, EffectcraftApp>, id: u64, secs: f64) {
let keys = json!([{"layer": id, "path": "transform/opacity", "time": secs}]);
h.state_mut().session.execute("keys.select", json!({"keys": keys, "selectProperties": true})).unwrap();
h.run_steps(2);
}
#[test]
fn the_selection_follows_the_box_while_it_is_dragged() {
let (mut h, id) = harness();
let (one, two) = (key_center(&h, id, 1.0), key_center(&h, id, 2.0));
let from = two + vec2(30.0, 5.0);
let (over_two, over_both) = (two + vec2(-30.0, -5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
drag(&mut h, from, over_two);
assert_eq!(selected(&h), [2.0], "the key the box reached is selected before the release");
assert_eq!(shown_layers(&h), [LayerId(id)], "and its layer, as the release selects it");
drag(&mut h, over_two, over_both);
assert_eq!(selected(&h), [1.0, 2.0], "the box grows over the next key");
drag(&mut h, over_both, over_two);
assert_eq!(selected(&h), [2.0], "the box shrinks off a key");
drag(&mut h, over_two, from + vec2(5.0, 0.0));
assert!(selected(&h).is_empty(), "the box leaves every key");
assert!(shown_layers(&h).is_empty(), "a box that catches nothing deselects (layers included)");
let end = from + vec2(5.0, 0.0);
drag(&mut h, end, over_two);
let shown = preview(&h).expect("the box shows a selection");
release_with(&mut h, over_two, Modifiers::default());
assert!(h.state().ui.timeline.marquee_preview.is_none(), "the release ends the preview");
assert_eq!(selected(&h), [2.0], "the release keeps what the box showed");
assert_eq!(selection(&h.state().session.state), shown, "layers, properties and keys alike");
}
#[test]
fn a_plain_box_replaces_the_selection_as_soon_as_it_starts() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let one = key_center(&h, id, 1.0);
let (from, past_key) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
drag(&mut h, from, one + vec2(20.0, -5.0));
assert!(selected(&h).is_empty(), "the box has caught nothing yet");
drag(&mut h, one + vec2(20.0, -5.0), past_key);
assert_eq!(selected(&h), [1.0]);
release_with(&mut h, past_key, Modifiers::default());
assert_eq!(selected(&h), [1.0]);
}
#[test]
fn a_shift_box_adds_to_the_selection_and_drops_only_what_it_added() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let one = key_center(&h, id, 1.0);
let (from, past_key, short) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0), one + vec2(20.0, -5.0));
press_with(&mut h, from, Modifiers::SHIFT);
drag(&mut h, from, short);
assert_eq!(selected(&h), [2.0], "Shift keeps the selection from before the drag");
drag(&mut h, short, past_key);
assert_eq!(selected(&h), [1.0, 2.0], "the box adds the key it reaches");
drag(&mut h, past_key, short);
assert_eq!(selected(&h), [2.0], "leaving the key drops it, but not the key selected before");
assert_eq!(shown_layers(&h), [LayerId(id)]);
drag(&mut h, short, past_key);
release_with(&mut h, past_key, Modifiers::SHIFT);
assert_eq!(selected(&h), [1.0, 2.0]);
}
#[test]
fn a_cmd_box_adds_to_the_selection_like_shift() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let one = key_center(&h, id, 1.0);
let (from, past_key) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::COMMAND);
drag(&mut h, from, past_key);
assert_eq!(selected(&h), [1.0, 2.0], "Cmd/Ctrl keeps the selection from before the drag");
release_with(&mut h, past_key, Modifiers::COMMAND);
assert_eq!(selected(&h), [1.0, 2.0]);
}
#[test]
fn a_box_over_only_locked_keys_still_clears_the_selection() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
h.state_mut().session.execute("layer.setSwitch", json!({"layers": [id], "switch": "locked", "value": true})).unwrap();
h.run_steps(2);
let one = key_center(&h, id, 1.0);
let (from, past_key) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
drag(&mut h, from, past_key);
release_with(&mut h, past_key, Modifiers::default());
let st = &h.state().session.state;
assert!(st.selected_keys.is_empty() && st.selected_props.is_empty() && st.selected_layers.is_empty(), "a box that catches nothing leaves nothing selected");
}
#[test]
fn escape_puts_back_the_selection_from_before_the_box() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let before = {
let st = &h.state().session.state;
(st.selected_keys.clone(), st.selected_props.clone(), st.selected_layers.clone())
};
assert_eq!(before.1.len(), 1, "the click selected the key's property");
let one = key_center(&h, id, 1.0);
let (from, past_key) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
drag(&mut h, from, past_key);
assert_eq!(selected(&h), [1.0], "the box replaced the selection");
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::NONE });
h.step();
let after = |h: &Harness<'_, EffectcraftApp>| {
let st = &h.state().session.state;
(st.selected_keys.clone(), st.selected_props.clone(), st.selected_layers.clone())
};
assert!(h.state().ui.timeline.marquee_preview.is_none(), "Escape drops the preview");
assert_eq!(after(&h), before, "Escape restores keys, properties and layers");
// The button is still down: neither moving on nor letting go brings the box back.
drag(&mut h, past_key, from);
drag(&mut h, from, past_key);
release_with(&mut h, past_key, Modifiers::default());
assert_eq!(after(&h), before, "the cancelled box is gone");
}
#[test]
fn a_box_makes_no_undo_step_and_selects_once_on_release() {
let (mut h, id) = harness();
let undo = h.state().session.history.undo.len();
let revision = h.state().session.revision;
let journal = h.state().session.journal.len();
let (one, two) = (key_center(&h, id, 1.0), key_center(&h, id, 2.0));
let from = two + vec2(30.0, 5.0);
let (over_two, over_both) = (two + vec2(-30.0, -5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
// 24 frames of movement: the box starts empty, then reaches one key, then the other.
drag(&mut h, from, over_two);
drag(&mut h, over_two, over_both);
drag(&mut h, over_both, over_both + vec2(-20.0, 0.0));
assert_eq!(selected(&h), [1.0, 2.0], "the rows show both keys before the release");
assert_eq!(h.state().session.journal.len(), journal, "the drag shows its selection without running commands");
release_with(&mut h, over_both + vec2(-20.0, 0.0), Modifiers::default());
assert_eq!(selected(&h), [1.0, 2.0]);
assert_eq!(h.state().session.history.undo.len(), undo, "selecting keys is no edit");
assert_eq!(h.state().session.revision, revision, "nor does it re-render the project");
let runs = h.state().session.journal.len() - journal;
assert!(runs <= 2, "the release runs one layer selection and one key selection at most: {runs}");
}
/// A Shift box that grows over a key and shrinks off it again, then is released: replaying the
/// recorded commands on a fresh document gives the selection the user saw.
#[test]
fn replaying_a_shift_box_that_grew_and_shrank_gives_the_live_selection() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let one = key_center(&h, id, 1.0);
let (from, past_key, short) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0), one + vec2(20.0, -5.0));
press_with(&mut h, from, Modifiers::SHIFT);
drag(&mut h, from, past_key);
assert_eq!(selected(&h), [1.0, 2.0], "the box grew over the key");
drag(&mut h, past_key, short);
assert_eq!(selected(&h), [2.0], "and shrank off it");
release_with(&mut h, short, Modifiers::SHIFT);
let live = selection(&h.state().session.state);
assert_eq!(selected(&h), [2.0], "the live selection is the key from before the box");
assert_eq!(replayed(&h), live, "the journal replays to the live selection");
// Grown again and released over the key, the replay keeps both.
press_with(&mut h, from, Modifiers::SHIFT);
drag(&mut h, from, past_key);
release_with(&mut h, past_key, Modifiers::SHIFT);
let live = selection(&h.state().session.state);
assert_eq!(selected(&h), [1.0, 2.0]);
assert_eq!(replayed(&h), live, "the journal replays to the live selection");
}
/// A box dragged over a key and cancelled with Escape: replaying the recorded commands on a
/// fresh document gives the selection from before the box.
#[test]
fn replaying_an_escaped_box_gives_the_live_selection() {
let (mut h, id) = harness();
select_key(&mut h, id, 2.0);
let one = key_center(&h, id, 1.0);
let (from, past_key) = (one + vec2(30.0, 5.0), one + vec2(-30.0, -5.0));
press_with(&mut h, from, Modifiers::default());
drag(&mut h, from, past_key);
assert_eq!(selected(&h), [1.0], "the box shows its key in place of the earlier one");
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::NONE });
h.step();
release_with(&mut h, past_key, Modifiers::default());
let live = selection(&h.state().session.state);
assert_eq!(selected(&h), [2.0], "Escape kept the earlier key");
assert_eq!(replayed(&h), live, "the journal replays to the live selection");
}
/// #3056: one box spans the layer outline and the time graph. Dragged from the empty outline
/// into the graph, or from the graph back over the outline, it selects the layers whose rows it
/// crosses and the keys inside it, through the real drag, release and selection commands.
@@ -269,6 +542,7 @@ fn cancellation_preserves_selection_and_does_not_restart_until_a_new_press() {
let to = c + vec2(10.0, 5.0);
press(&mut h, c - vec2(20.0, 5.0), to);
assert_eq!(times(&h), [2.0], "selection commits only on release");
assert_eq!(selected(&h), [1.0], "the rows show the box's selection as it moves (#2858)");
match cancel {
"escape" => h.event(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }),
"ownership" => h.ctx.set_dragged_id(egui::Id::unique("another-owner")),