Project: a Cut is read with the modifiers held where it is in the frame (#484)
Cause: clipboard events carry no modifiers, and the Cut and Copy/Paste mapping read i.modifiers, egui's state after all of the frame's events. A Shift+Delete with Shift released in the same frame became Ctrl+X (no deletion), and a Ctrl+X followed in the same frame by Ctrl up and Shift down became Shift+Delete: the selected items and the layers using them deleted without the prompt. Fix: walk the frame's events in order from the modifiers held when it began (the state the last pass ended with, recorded each pass), so each Cut, Copy and Paste uses the modifiers at its place in the stream. When that state isn't known (a pass was skipped), a Cut is never Shift+Delete. Only Shift alone counts, not Ctrl/Alt+Shift. Tests: a_cut_is_read_with_the_modifiers_where_it_is_in_the_frame queues modifier changes and a Cut in one frame (Shift then Cut and Shift up; Ctrl, Cut, Ctrl up, Shift down; and the mixed orders); the Windows Shift+Delete helper now sends Shift, Cut and Shift up as one frame. They fail on the previous mapping and pass now.
This commit is contained in:
@@ -63,17 +63,18 @@ enum ShiftDelete {
|
||||
fn shift_delete(h: &mut Harness<'_, EffectcraftApp>, how: ShiftDelete) {
|
||||
match how {
|
||||
ShiftDelete::Key => key(h, Key::Delete, Modifiers::SHIFT),
|
||||
ShiftDelete::WindowsCut => {
|
||||
h.input_mut().events.push(Event::ModifiersChanged(Modifiers::SHIFT));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::Cut);
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::ModifiersChanged(Modifiers::NONE));
|
||||
h.run_steps(2);
|
||||
}
|
||||
// Shift down, Cut and Shift up all in one frame.
|
||||
ShiftDelete::WindowsCut => frame(h, &[Event::ModifiersChanged(Modifiers::SHIFT), Event::Cut, Event::ModifiersChanged(Modifiers::NONE)]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Queue `events` together and run them as one frame.
|
||||
fn frame(h: &mut Harness<'_, EffectcraftApp>, events: &[Event]) {
|
||||
h.input_mut().events.extend(events.iter().cloned());
|
||||
h.step();
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
const SHIFT_DELETE: [ShiftDelete; 2] = [ShiftDelete::Key, ShiftDelete::WindowsCut];
|
||||
|
||||
/// Items that compositions use ask first, as in After Effects: answer Delete when asked.
|
||||
@@ -336,3 +337,30 @@ fn shift_delete_in_other_panels_keeps_project_items() {
|
||||
assert!(items.iter().all(|i| h.state().session.project.item(*i).is_some()), "{how:?} in the Composition panel");
|
||||
}
|
||||
}
|
||||
|
||||
/// A Cut is read with the modifiers held where it is among the frame's events, not those held
|
||||
/// after the frame: Shift released in the same frame is still Shift+Delete, and a Ctrl+X followed
|
||||
/// in the same frame by Ctrl up and Shift down is not.
|
||||
#[test]
|
||||
fn a_cut_is_read_with_the_modifiers_where_it_is_in_the_frame() {
|
||||
use Event::{Cut, ModifiersChanged as M};
|
||||
let (shift, ctrl, none) = (Modifiers::SHIFT, Modifiers::COMMAND, Modifiers::NONE);
|
||||
// (held from the frame before, this frame's events, whether the solid in use goes)
|
||||
let cases: [(Modifiers, Vec<Event>, bool); 5] = [
|
||||
(shift, vec![Cut, M(none)], true),
|
||||
(ctrl, vec![Cut, M(none), M(shift)], false),
|
||||
(none, vec![M(shift), Cut, M(none)], true),
|
||||
(none, vec![M(ctrl), Cut, M(none), M(shift)], false),
|
||||
(shift, vec![M(none), Cut, M(shift)], false),
|
||||
];
|
||||
for (n, (before, events, deletes)) in cases.into_iter().enumerate() {
|
||||
let (mut h, items, _) = harness();
|
||||
let solid = items[1];
|
||||
click(&mut h, &format!("project.item.{}.name", solid.0), Modifiers::NONE);
|
||||
frame(&mut h, &[M(before)]);
|
||||
frame(&mut h, &events);
|
||||
frame(&mut h, &[M(none)]);
|
||||
assert_eq!(h.state().dialog, None, "case {n}: no prompt");
|
||||
assert_eq!(h.state().session.project.item(solid).is_none(), deletes, "case {n}: {events:?} after {before:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user