Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Escape cancels a value drag, color pick or dialog drag in progress (#580)

ReReddo6b7f48d04dc7
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index a2ed9e6a2..1d53fe201 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -192,6 +192,10 @@ impl Services for FsServices {
}
}
+/// A point in the undo history (its top step), from [`Session::undo_mark`].
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct UndoMark(Option<usize>);
+
/// Undo history of whole-project snapshots.
#[derive(Clone, Default)]
pub struct History {
@@ -833,6 +837,36 @@ impl Session {
Ok(r)
}
+ /// Where the undo history stands now, for [`Session::revert_to`].
+ pub fn undo_mark(&self) -> UndoMark {
+ UndoMark(self.history.undo.last().map(|u| Arc::as_ptr(&u.1) as usize))
+ }
+
+ /// Take back every edit made since `mark` (a gesture cancelled with Escape, #580), merged or
+ /// not: the project returns to how it was at `mark`, and neither undo nor redo keeps them.
+ /// Nothing happens when `mark` has left the history. Returns how many steps were taken back.
+ pub fn revert_to(&mut self, mark: UndoMark) -> usize {
+ if let UndoMark(Some(p)) = mark
+ && !self.history.undo.iter().any(|u| Arc::as_ptr(&u.1) as usize == p)
+ {
+ return 0;
+ }
+ let mut earliest = None;
+ let mut n = 0;
+ while self.undo_mark() != mark {
+ let Some((_, prev)) = self.history.undo.pop() else { break };
+ earliest = Some(prev);
+ n += 1;
+ }
+ if let Some(prev) = earliest {
+ self.project = prev;
+ self.history.merge_key = None;
+ self.fix_state();
+ self.bump();
+ }
+ n
+ }
+
/// Edit the active sequence with the edit-algebra context.
pub fn edit_sequence<R>(&mut self, label: &str, f: impl FnOnce(&mut Sequence, &mut EditCtx, &mut EditorState) -> Result<R>) -> Result<R> {
self.edit_sequence_as(label, None, f)
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 9852734d7..e3905d6b2 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -958,3 +958,47 @@ fn enable_flips_each_selected_clip() {
s.execute("clip.enable", json!({"clips": [a, b]})).unwrap();
assert_eq!((enabled(&s, a), enabled(&s, b)), (true, true));
}
+
+/// #580: Escape takes back what a gesture changed, merged or not: the project returns to the mark,
+/// neither undo nor redo keeps the changes, and older steps stay.
+#[test]
+fn reverting_to_a_mark_takes_back_a_gesture_without_redo() {
+ let mut s = demo_unlocked();
+ let id = v1(&s)[0].0;
+ let opacity = |s: &Session| {
+ let q = s.active_sequence().unwrap();
+ let it = q.find_item(ClipId(id)).unwrap().1;
+ it.effects.iter().find(|e| e.effect == "opacity").unwrap().params["opacity"].value.as_f64().unwrap()
+ };
+ let set = |s: &mut Session, v: f64, merge: bool, begin: bool| {
+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": v, "merge": merge, "begin": begin})).unwrap();
+ };
+ set(&mut s, 80.0, false, false); // an earlier edit, kept
+ let (start, undo, mark) = (opacity(&s), s.history.undo.len(), s.undo_mark());
+ set(&mut s, 90.0, true, true); // a merged drag…
+ set(&mut s, 70.0, true, false);
+ set(&mut s, 60.0, false, false); // …and changes made one step each
+ set(&mut s, 50.0, false, false);
+ assert_eq!(s.revert_to(mark), 3);
+ assert_eq!(opacity(&s), start, "the value at the mark");
+ assert_eq!(s.history.undo.len(), undo, "the earlier step stays");
+ assert!(s.history.redo.is_empty(), "nothing to redo");
+ assert_eq!(s.revert_to(mark), 0, "nothing left to take back");
+ s.undo();
+ assert_eq!(opacity(&s), 100.0, "undo still takes back the earlier edit");
+}
+
+/// A mark no longer in the history does nothing; an older mark still takes back what followed it.
+#[test]
+fn reverting_to_a_lost_mark_does_nothing() {
+ let mut s = demo_unlocked();
+ let id = v1(&s)[0].0;
+ let (base, start) = (s.history.undo.len(), s.undo_mark());
+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": 40.0})).unwrap();
+ let mark = s.undo_mark();
+ s.undo();
+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": 30.0})).unwrap();
+ assert_eq!(s.revert_to(mark), 0, "the marked step was undone and replaced");
+ assert_eq!(s.revert_to(start), 1);
+ assert_eq!(s.history.undo.len(), base);
+}
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index 23b4b6cc1..515624e01 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -722,6 +722,19 @@ pub fn draw_group_chrome_details(
if resp.dragged() {
dragged = Some(id);
}
+ // Escape puts a dragged tab back where it was (egui ends the drag on Escape, #580)
+ let home = egui::Id::new(("tab-seq-home", id));
+ if resp.drag_started()
+ && let Some(at) = seqs.open.iter().position(|(s, _)| *s == id)
+ {
+ ui.data_mut(|d| d.insert_temp(home, at));
+ }
+ if resp.drag_stopped()
+ && let Some(at) = ui.data_mut(|d| d.remove_temp::<usize>(home))
+ && ui.input(|i| i.key_pressed(egui::Key::Escape))
+ {
+ actions.push(DockAction::MoveSequence(id, at));
+ }
}
if let Some(id) = tab.seq {
reg.add_response(&format!("timeline.tab.{id}"), &resp, &tab.title);
diff --git a/crates/ui-egui/src/dock_ui.rs b/crates/ui-egui/src/dock_ui.rs
index d90888abf..bc368cff7 100644
--- a/crates/ui-egui/src/dock_ui.rs
+++ b/crates/ui-egui/src/dock_ui.rs
@@ -255,6 +255,7 @@ impl FilmcraftApp {
}
self.panel_drag(&ctx, &targets);
panels::panel_menu_popup(self, ui);
+ self.cancel_value_drag(ui.ctx());
}
fn floating_group(&mut self, ctx: &egui::Context, index: usize, seqs: &dock::SeqTabs, actions: &mut Vec<DockAction>) -> Option<DropTarget<PanelKind>> {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 438112a29..455bff6f6 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -279,6 +279,9 @@ pub struct FilmcraftApp {
deferred: Vec<(ControlRequest, f64)>,
last_ui_time: f64,
pub(crate) synthetic: Vec<egui::Event>,
+ /// The mouse press in progress (its start time) and the undo history when it began, for Escape
+ /// to take back what the press changed (#580).
+ value_press: Option<(f64, filmcraft_engine::UndoMark)>,
/// BS.1770 loudness of the programme as it plays, and the next sample position to feed.
pub(crate) loudness: Option<(filmcraft_audio_dsp::LoudnessMeter, i64)>,
/// Status message last shown and when it first appeared (messages expire after a few seconds).
@@ -519,6 +522,7 @@ impl FilmcraftApp {
deferred: Vec::new(),
last_ui_time: 0.0,
synthetic: Vec::new(),
+ value_press: None,
loudness: None,
status_seen: (String::new(), 0.0),
pending_screenshots: Vec::new(),
@@ -1651,6 +1655,7 @@ impl FilmcraftApp {
}
self.command_inbox = Some(rx);
}
+ self.begin_press(&ctx);
self.handle_shortcuts(&ctx);
self.advance_playback(&ctx);
self.advance_source_playback(&ctx);
@@ -1788,6 +1793,29 @@ impl FilmcraftApp {
}
.to_string()
}
+
+ /// Remember the undo history as a mouse press begins, before any panel acts on it (a color
+ /// picker sets its color on the press itself), for [`Self::cancel_value_drag`].
+ fn begin_press(&mut self, ctx: &egui::Context) {
+ match ctx.input(|i| i.pointer.press_start_time().filter(|_| i.pointer.any_down())) {
+ None => self.value_press = None,
+ Some(p) if self.value_press.is_some_and(|(q, _)| q == p) => {}
+ Some(p) => self.value_press = Some((p, self.session.undo_mark())),
+ }
+ }
+
+ /// Escape while a mouse button is held takes back every edit this press made (#580): value
+ /// drags (one merged step or one step per change), color picks, anything committed on the
+ /// Escape frame. Run after the panels, so a value sent on the Escape frame goes with it.
+ fn cancel_value_drag(&mut self, ctx: &egui::Context) {
+ let escape = ctx.input(|i| i.pointer.any_down() && i.key_pressed(egui::Key::Escape));
+ if let Some((press, mark)) = self.value_press
+ && escape
+ && self.session.revert_to(mark) > 0
+ {
+ self.value_press = Some((press, self.session.undo_mark()));
+ }
+ }
}
impl FilmcraftApp {
diff --git a/crates/ui-egui/src/panels/audio_fx_editor.rs b/crates/ui-egui/src/panels/audio_fx_editor.rs
index bccdd0ad7..ba86d691a 100644
--- a/crates/ui-egui/src/panels/audio_fx_editor.rs
+++ b/crates/ui-egui/src/panels/audio_fx_editor.rs
@@ -113,6 +113,19 @@ impl Ed<'_> {
// keep showing the new value until the project catches up this frame
self.drafts.insert(pid.to_string(), v);
}
+ /// The end of a drag of `pids`: commit their drafts, or drop them when Escape ended the drag
+ /// (egui ends a drag on Escape, #580).
+ fn release(&mut self, ui: &egui::Ui, pids: &[&str]) {
+ let escape = ui.input(|i| i.key_pressed(egui::Key::Escape));
+ for pid in pids {
+ if escape {
+ self.drafts.remove(*pid);
+ } else {
+ let v = self.v(pid);
+ self.commit(pid, v);
+ }
+ }
+ }
fn auto(&mut self, id: String, r: Rect, label: &str) {
self.autos.push((id, r, label.to_string()));
}
@@ -144,7 +157,9 @@ impl Ed<'_> {
if r.dragged() {
self.drafts.insert(pid.to_string(), v);
}
- if r.drag_stopped() || (r.changed() && !r.dragged()) {
+ if r.drag_stopped() {
+ self.release(ui, &[pid]);
+ } else if r.changed() && !r.dragged() {
self.commit(pid, v);
}
}
@@ -324,12 +339,8 @@ fn parametric(ui: &mut egui::Ui, ed: &mut Ed) {
}
}
if resp.drag_stopped() {
- let fv = ed.v(&f_id);
- ed.commit(&f_id, fv);
- if gain {
- let gv = ed.v(&g_id);
- ed.commit(&g_id, gv);
- }
+ let pids = if gain { vec![f_id.as_str(), g_id.as_str()] } else { vec![f_id.as_str()] };
+ ed.release(ui, &pids);
}
// scroll over a node changes its Q
if gain && resp.hovered() {
@@ -393,8 +404,7 @@ fn graphic(ui: &mut egui::Ui, ed: &mut Ed) {
ed.drafts.insert(pid.clone(), (db * 2.0).round() / 2.0);
}
if resp.drag_stopped() {
- let nv = ed.v(&pid);
- ed.commit(&pid, nv);
+ ed.release(ui, &[pid.as_str()]);
}
if resp.double_clicked() {
ed.commit(&pid, 0.0);
@@ -472,8 +482,7 @@ fn multiband(ui: &mut egui::Ui, ed: &mut Ed) {
ed.drafts.insert(pid.to_string(), fx_of(pos.x, r).clamp(lo, hi).round());
}
if resp.drag_stopped() {
- let v = ed.v(pid);
- ed.commit(pid, v);
+ ed.release(ui, &[pid]);
}
}
ui.add_space(4.0);
diff --git a/crates/ui-egui/src/panels/clip_dialogs.rs b/crates/ui-egui/src/panels/clip_dialogs.rs
index 2d5b8b536..7667eefe2 100644
--- a/crates/ui-egui/src/panels/clip_dialogs.rs
+++ b/crates/ui-egui/src/panels/clip_dialogs.rs
@@ -299,6 +299,7 @@ fn frames(ui: &mut egui::Ui, elems: &mut Elems, pre: &str, p: &mut Value, key: &
/// Draw the open dialog, if any.
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.clip_dialog.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("clip-dialog-before-drag"), &mut d);
let Some((title, pre)) = meta(&d.command) else {
app.ui.clip_dialog = None;
return;
@@ -581,7 +582,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
if action.is_some() {
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index 40ffadc64..e49e4c412 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -39,7 +39,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
.resizable(false)
.anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0))
.show(ctx, |ui| about(app, ui));
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
open = false;
}
}
@@ -104,6 +104,7 @@ fn audio_gain(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
}
};
let mut draft = app.ui.audio_gain.clone();
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("audio-gain-before-drag"), &mut draft);
let mut keep = true;
let mut apply = false;
let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
@@ -153,7 +154,7 @@ fn audio_gain(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
keep = false;
}
if apply {
@@ -188,6 +189,7 @@ fn add_tracks(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
let names = |tracks: &[filmcraft_engine::project::Track]| tracks.iter().map(|t| t.name.clone()).collect::<Vec<_>>();
let (vnames, anames, snames) = (names(&seq.video_tracks), names(&seq.audio_tracks), names(&seq.submix_tracks));
let mut d = app.ui.add_tracks.clone();
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("add-tracks-before-drag"), &mut d);
let mut keep = true;
let mut apply = false;
let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
@@ -282,7 +284,7 @@ fn add_tracks(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
keep = false;
}
if ctx.input(|i| i.key_pressed(egui::Key::Enter)) && !ctx.egui_wants_keyboard_input() {
@@ -379,7 +381,7 @@ fn delete_tracks(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
keep = false;
}
if apply {
diff --git a/crates/ui-egui/src/panels/effect_controls.rs b/crates/ui-egui/src/panels/effect_controls.rs
index 6b071c4ca..7c0e943c1 100644
--- a/crates/ui-egui/src/panels/effect_controls.rs
+++ b/crates/ui-egui/src/panels/effect_controls.rs
@@ -669,7 +669,10 @@ pub(crate) fn param_row(
let off = drag_off.unwrap_or(0.0) + resp.drag_delta().x;
ui.data_mut(|d| d.insert_temp(id, off));
}
- if resp.drag_stopped() {
+ // egui ends a drag on Escape: that stop abandons it (#580)
+ if resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ ui.data_mut(|d| d.remove::<f32>(id));
+ } else if resp.drag_stopped() {
let off = drag_off.unwrap_or(0.0);
ui.data_mut(|d| d.remove::<f32>(id));
let new_tl =
@@ -960,11 +963,12 @@ pub fn properties_panel(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
run(app, ui.ctx(), actions);
}
-/// Run the panel's actions. Parameter changes made while the mouse button is down (a drag) share
-/// one undo step, which the first change of each press begins (#201); typed values and clicks stay
-/// separate steps. A drag value only changes once the mouse moves, after the press frame, so the
-/// press that already began a step is remembered by its start time.
-fn run(app: &mut FilmcraftApp, ctx: &egui::Context, actions: Vec<(String, Value)>) {
+/// Run the panel's actions (also the Lumetri Color panel's). Parameter changes made
+/// while the mouse button is down (a drag) share one undo step, which the first change of each
+/// press begins (#201); typed values and clicks stay separate steps. A drag value only changes once
+/// the mouse moves, after the press frame, so the press that already began a step is remembered by
+/// its start time.
+pub(crate) fn run(app: &mut FilmcraftApp, ctx: &egui::Context, actions: Vec<(String, Value)>) {
let (down, press) = ctx.input(|i| (i.pointer.any_down(), i.pointer.press_start_time()));
let key = egui::Id::new("effect-controls-drag-step");
for (cmd, mut p) in actions {
@@ -1142,7 +1146,9 @@ pub(crate) fn graph_rows(
let nx = graph_drag_offset(ui, &hr, vec2(hdx, 0.0)).x;
ui.data_mut(|d| d.insert_temp(hid, nx));
}
- if hr.drag_stopped() {
+ if hr.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ ui.data_mut(|d| d.remove::<f32>(hid));
+ } else if hr.drag_stopped() {
ui.data_mut(|d| d.remove::<f32>(hid));
let ni = ((infl * seg + hdx * side) / seg.max(1.0)).clamp(0.01, 1.0);
let key = if side > 0.0 { "outInfluence" } else { "inInfluence" };
@@ -1158,7 +1164,10 @@ pub(crate) fn graph_rows(
ui.data_mut(|d| d.insert_temp(id, ny));
p.text(c + vec2(8.0, -10.0), Align2::LEFT_BOTTOM, format!("{:.dec$}", v_of(c.y)), Tokens::ui(10.5), t.hot_text);
}
- if resp.drag_stopped() {
+ // egui ends a drag on Escape: that stop abandons it (#580)
+ if resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ ui.data_mut(|d| d.remove::<f32>(id));
+ } else if resp.drag_stopped() {
ui.data_mut(|d| d.remove::<f32>(id));
let nv = v_of(c.y);
let nv = if let ParamKind::Float { min, max, .. } = pd.kind { nv.clamp(min, max) } else { nv };
diff --git a/crates/ui-egui/src/panels/export_mode.rs b/crates/ui-egui/src/panels/export_mode.rs
index 30d21268e..0bf753885 100644
--- a/crates/ui-egui/src/panels/export_mode.rs
+++ b/crates/ui-egui/src/panels/export_mode.rs
@@ -342,8 +342,21 @@ fn section(ui: &mut egui::Ui, reg: &mut Reg, open: &mut Vec<String>, key: &str,
}
fn drag(ui: &mut egui::Ui, reg: &mut Reg, id: &str, v: &mut f64, range: std::ops::RangeInclusive<f64>, speed: f64, suffix: &str, decimals: usize) -> bool {
+ let before = *v;
let r = ui.add(egui::DragValue::new(v).range(range).speed(speed).suffix(suffix).max_decimals(decimals));
reg.add(id, r.rect, format!("{v}"));
+ // a drag ended by Escape goes back to the value it started from (egui ends the drag, #580)
+ let home = r.id.with("before-drag");
+ if r.drag_started() {
+ ui.data_mut(|d| d.insert_temp(home, before));
+ }
+ if r.drag_stopped()
+ && let Some(b) = ui.data_mut(|d| d.remove_temp::<f64>(home))
+ && ui.input(|i| i.key_pressed(egui::Key::Escape))
+ {
+ *v = b;
+ return true;
+ }
r.changed()
}
@@ -1205,7 +1218,7 @@ fn preset_manager(app: &mut FilmcraftApp, ctx: &egui::Context) {
{
close = true;
}
- app.ui.export.manager = if close || !open || ctx.input(|i| i.key_pressed(egui::Key::Escape)) { None } else { Some(m) };
+ app.ui.export.manager = if close || !open || crate::widgets::escape_closes(ctx) { None } else { Some(m) };
}
/// A five-pointed star (favourite marker), drawn from scratch.
@@ -1326,7 +1339,7 @@ pub fn quick_export(app: &mut FilmcraftApp, ctx: &egui::Context, anchor: egui::P
}
close = true;
}
- if close || ctx.input(|i| i.key_pressed(egui::Key::Escape)) || (clicked_elsewhere && !toggled) {
+ if close || crate::widgets::escape_closes(ctx) || (clicked_elsewhere && !toggled) {
app.ui.export.quick_open = false;
}
}
diff --git a/crates/ui-egui/src/panels/file_dialogs.rs b/crates/ui-egui/src/panels/file_dialogs.rs
index 6266b59fa..26015da3a 100644
--- a/crates/ui-egui/src/panels/file_dialogs.rs
+++ b/crates/ui-egui/src/panels/file_dialogs.rs
@@ -130,7 +130,8 @@ pub fn show_revert(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
});
});
});
- open && !r.should_close()
+ // (the modal's own close also fires on Escape: not while a drag is being cancelled, #580)
+ open && !(r.should_close() && !ctx.input(|i| i.pointer.any_down()))
}
/// Draw the dialog if it is one of ours; returns Some(still open).
diff --git a/crates/ui-egui/src/panels/frame_export.rs b/crates/ui-egui/src/panels/frame_export.rs
index 4790c440a..33ec63f7e 100644
--- a/crates/ui-egui/src/panels/frame_export.rs
+++ b/crates/ui-egui/src/panels/frame_export.rs
@@ -208,7 +208,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, rect, label) in elems {
app.auto.add(&id, rect, &label);
}
- close |= ctx.input(|i| i.key_pressed(egui::Key::Escape));
+ close |= crate::widgets::escape_closes(ctx);
if browse && !close {
let folder = filmcraft_engine::export_tools::expand_home(d.folder.trim());
let picked = match app.hooks.pick_folder_at.as_mut() {
diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rs
index 7cf5f47b3..558e4dcb6 100644
--- a/crates/ui-egui/src/panels/graphics.rs
+++ b/crates/ui-egui/src/panels/graphics.rs
@@ -753,7 +753,8 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
}
if resp.drag_stopped() {
ui.data_mut(|dd| dd.remove::<DragState>(drag_id));
- let moved = (cur - d.start).length() > 2.0;
+ // egui ends a drag on Escape: that stop abandons it (#580)
+ let moved = (cur - d.start).length() > 2.0 && !ui.input(|i| i.key_pressed(egui::Key::Escape));
match d.kind {
DragKind::Move if moved => {
if let Some(v) = v {
@@ -1792,7 +1793,7 @@ pub fn properties(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
pub fn dialogs(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.text_props_dialog.clone() else { return };
let mut elems: Vec<(String, Rect, &str)> = Vec::new();
- let mut close = ctx.input(|i| i.key_pressed(egui::Key::Escape));
+ let mut close = crate::widgets::escape_closes(ctx);
let mut ok = false;
let name = |paragraph: bool| if paragraph { tl!("Paragraph Text") } else { tl!("Point Text") };
let id = egui::Id::new("gfx-text-properties");
diff --git a/crates/ui-egui/src/panels/interchange_export.rs b/crates/ui-egui/src/panels/interchange_export.rs
index 205cdafa9..427572e9d 100644
--- a/crates/ui-egui/src/panels/interchange_export.rs
+++ b/crates/ui-egui/src/panels/interchange_export.rs
@@ -62,6 +62,7 @@ pub fn is_open(ctx: &egui::Context) -> bool {
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(Some(mut d)) = ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())) else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("interchange-export-before-drag"), &mut d);
let p = if d.omf { "omfExport" } else { "aafExport" };
let mut close = false;
let mut apply = false;
@@ -168,7 +169,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
close = true;
}
if apply {
diff --git a/crates/ui-egui/src/panels/lumetri.rs b/crates/ui-egui/src/panels/lumetri.rs
index ff35ec199..3a9e2da76 100644
--- a/crates/ui-egui/src/panels/lumetri.rs
+++ b/crates/ui-egui/src/panels/lumetri.rs
@@ -235,11 +235,8 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
app.auto.add(&id, r, label);
}
}
- for a in actions {
- if let Err(err) = app.session.execute("effects.setParam", a) {
- app.ui.status = err.to_string();
- }
- }
+ // a dragged value is one undo step, as in Effect Controls
+ crate::panels::effect_controls::run(app, ui.ctx(), actions.into_iter().map(|a| ("effects.setParam".to_string(), a)).collect());
for sec in sections {
if let Err(err) = app.session.execute("lumetri.setSection", json!({"clip": clip.0, "section": sec})) {
app.ui.status = err.to_string();
diff --git a/crates/ui-egui/src/panels/media_browser.rs b/crates/ui-egui/src/panels/media_browser.rs
index 592abb20e..256fc6fa7 100644
--- a/crates/ui-egui/src/panels/media_browser.rs
+++ b/crates/ui-egui/src/panels/media_browser.rs
@@ -232,10 +232,22 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let mut sz = prefs.thumbnail_size;
let resp = ui.put(sr, egui::Slider::new(&mut sz, 60.0..=320.0).show_value(false));
app.auto.add("mediaBrowser.thumbnailSize", sr, "Thumbnail size");
+ // a drag ended by Escape goes back to the size it started from (#580)
+ let orig_id = egui::Id::new("media-browser-thumbnail-size-before-drag");
+ if resp.drag_started() {
+ ui.data_mut(|d| d.insert_temp(orig_id, prefs.thumbnail_size));
+ }
+ let escaped = resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape));
+ if resp.drag_stopped()
+ && let Some(before) = ui.data_mut(|d| d.remove_temp(orig_id))
+ && escaped
+ {
+ sz = before;
+ }
if sz != prefs.thumbnail_size {
app.session.prefs.media_browser.thumbnail_size = sz;
}
- if resp.drag_stopped() || (resp.changed() && !resp.dragged()) {
+ if !escaped && (resp.drag_stopped() || (resp.changed() && !resp.dragged())) {
exec(app, &ctx, "mediaBrowser.settings", json!({"thumbnailSize": sz}));
}
}
@@ -839,5 +851,5 @@ pub fn dialogs(app: &mut FilmcraftApp, ctx: &egui::Context) {
}
close = true;
}
- app.ui.media_browser.edit_columns = if close || ctx.input(|i| i.key_pressed(egui::Key::Escape)) { None } else { Some(cols) };
+ app.ui.media_browser.edit_columns = if close || crate::widgets::escape_closes(ctx) { None } else { Some(cols) };
}
diff --git a/crates/ui-egui/src/panels/media_dialogs.rs b/crates/ui-egui/src/panels/media_dialogs.rs
index cef30cd83..c61adef31 100644
--- a/crates/ui-egui/src/panels/media_dialogs.rs
+++ b/crates/ui-egui/src/panels/media_dialogs.rs
@@ -298,7 +298,7 @@ fn link_media(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
let (item, ..) = rows[d.row].clone();
@@ -424,7 +424,7 @@ fn make_offline(app: &mut FilmcraftApp, ctx: &egui::Context) {
}
keep = false;
}
- app.ui.make_offline = (keep && !ctx.input(|i| i.key_pressed(egui::Key::Escape))).then_some(delete);
+ app.ui.make_offline = (keep && !crate::widgets::escape_closes(ctx)).then_some(delete);
}
fn create_proxies(app: &mut FilmcraftApp, ctx: &egui::Context) {
@@ -483,7 +483,7 @@ fn create_proxies(app: &mut FilmcraftApp, ctx: &egui::Context) {
}
keep = false;
}
- app.ui.create_proxies = (keep && !ctx.input(|i| i.key_pressed(egui::Key::Escape))).then_some(d);
+ app.ui.create_proxies = (keep && !crate::widgets::escape_closes(ctx)).then_some(d);
}
fn pm_params(d: &ProjectManagerDraft, dry: bool) -> Value {
@@ -502,6 +502,7 @@ fn pm_params(d: &ProjectManagerDraft, dry: bool) -> Value {
fn project_manager(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.project_manager.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("project-manager-before-drag"), &mut d);
let before = d.clone();
let mut elems: Elems = Vec::new();
let mut keep = true;
@@ -633,5 +634,5 @@ fn project_manager(app: &mut FilmcraftApp, ctx: &egui::Context) {
Err(e) => d.message = e.to_string(),
}
}
- app.ui.project_manager = (keep && !ctx.input(|i| i.key_pressed(egui::Key::Escape))).then_some(d);
+ app.ui.project_manager = (keep && !crate::widgets::escape_closes(ctx)).then_some(d);
}
diff --git a/crates/ui-egui/src/panels/menu_dialogs.rs b/crates/ui-egui/src/panels/menu_dialogs.rs
index 1d35c21e8..0891b8bae 100644
--- a/crates/ui-egui/src/panels/menu_dialogs.rs
+++ b/crates/ui-egui/src/panels/menu_dialogs.rs
@@ -446,6 +446,7 @@ fn pairs(v: &[&str]) -> Vec<(String, String)> {
/// Draw the open dialog, if any.
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.extras.dialog.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("menu-dialog-before-drag"), &mut d);
let Some((title, pre, ok_text)) = meta(&d.command) else {
app.ui.extras.dialog = None;
return;
@@ -828,7 +829,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
{
d.params[k.as_str()] = json!(dir);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
match action {
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index 768a9474a..cc8926ffe 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -339,7 +339,7 @@ pub fn panel_menu_popup(app: &mut FilmcraftApp, ui: &mut egui::Ui) {
// A click elsewhere or Escape closes the menu. The click that opened it is over the tab, not
// the menu, and must not close it again in the same frame.
let fresh = ui.ctx().data(|d| d.get_temp::<u64>(egui::Id::new("panel-menu-opened"))) == Some(ui.ctx().cumulative_frame_nr());
- if close || (!fresh && area.response.clicked_elsewhere()) || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if close || (!fresh && area.response.clicked_elsewhere()) || crate::widgets::escape_closes(ui.ctx()) {
ui.ctx().data_mut(|d| d.remove::<(PanelKind, egui::Pos2)>(id));
}
}
diff --git a/crates/ui-egui/src/panels/monitor_view.rs b/crates/ui-egui/src/panels/monitor_view.rs
index 501ead7a5..fffe84e09 100644
--- a/crates/ui-egui/src/panels/monitor_view.rs
+++ b/crates/ui-egui/src/panels/monitor_view.rs
@@ -523,7 +523,8 @@ pub fn rulers(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, top: Rect, le
}
if resp.drag_stopped() {
ui.data_mut(|d| d.remove::<NewGuide>(drag_id));
- if area.contains(pos) {
+ // egui ends a drag on Escape: that stop adds no guide (#580)
+ if area.contains(pos) && !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
let position = if ng.vertical { ((pos.x - pic.min.x) / kx).round() } else { ((pos.y - pic.min.y) / ky).round() } as f64;
let v = view_mut(app, w);
v.guides.push(Guide { vertical: ng.vertical, position });
@@ -561,6 +562,20 @@ pub fn guides(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, area: Rect, p
if resp.hovered() || resp.dragged() {
ui.ctx().set_cursor_icon(if g.vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical });
}
+ // egui ends a drag on Escape: that stop puts the guide back where it was (#580)
+ let before_id = egui::Id::new((pfx, "guide-before-drag", i));
+ if resp.drag_started() {
+ ui.data_mut(|d| d.insert_temp(before_id, g.position));
+ }
+ if resp.drag_stopped() {
+ let before = ui.data_mut(|d| d.remove_temp::<f64>(before_id));
+ if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if let (Some(p0), Some(guide)) = (before, view_mut(app, w).guides.get_mut(i)) {
+ guide.position = p0;
+ }
+ continue;
+ }
+ }
if let Some(pos) = resp.interact_pointer_pos()
&& (resp.dragged() || resp.drag_stopped())
{
@@ -775,8 +790,9 @@ fn push(e: &mut Elems, id: &str, r: &egui::Response, label: &str) {
/// Add Guide… / Save Guides as Template… / Manage Guides… dialogs.
pub fn dialogs(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.guide_dialog.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("guide-dialog-before-drag"), &mut d);
let mut elems: Elems = Vec::new();
- let mut close = ctx.input(|i| i.key_pressed(egui::Key::Escape));
+ let mut close = crate::widgets::escape_closes(ctx);
let mut act: Option<(String, Value)> = None;
let templates: Vec<String> = app.session.prefs.guides.templates.iter().map(|t| t.name.clone()).collect();
let (title, shown) = match &d {
diff --git a/crates/ui-egui/src/panels/multicam.rs b/crates/ui-egui/src/panels/multicam.rs
index b5403b3d6..4fa87de29 100644
--- a/crates/ui-egui/src/panels/multicam.rs
+++ b/crates/ui-egui/src/panels/multicam.rs
@@ -93,6 +93,7 @@ fn methods() -> [(&'static str, &'static str); 5] {
/// Draw the open Synchronize / Merge Clips / Create Multi-Camera dialog.
pub fn show_dialog(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.sync_dialog.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("sync-dialog-before-drag"), &mut d);
let (title, pre) = match d.kind.as_str() {
"merge" => (tl!("Merge Clips"), "merge"),
"multicam" => (tl!("Create Multi-Camera Source Sequence"), "mcam"),
@@ -213,7 +214,7 @@ pub fn show_dialog(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
match action {
@@ -498,7 +499,7 @@ pub fn show_edit_cameras(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
match action {
diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs
index 95932cb16..9a0e167d8 100644
--- a/crates/ui-egui/src/panels/project.rs
+++ b/crates/ui-egui/src/panels/project.rs
@@ -579,13 +579,25 @@ fn footer(app: &mut FilmcraftApp, ui: &mut egui::Ui, bar: Rect, v: &View, action
let mut sz = v.icon_size;
let resp = ui.put(sr, egui::Slider::new(&mut sz, 48.0..=400.0).show_value(false));
app.auto.add(&format!("{pre}.iconSize"), sr, "Zoom");
+ // a drag ended by Escape goes back to the size it started from (#580)
+ let orig_id = egui::Id::new((pre, "icon-size-before-drag"));
+ if resp.drag_started() {
+ ui.data_mut(|d| d.insert_temp(orig_id, v.icon_size));
+ }
+ let escaped = resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape));
+ if resp.drag_stopped()
+ && let Some(before) = ui.data_mut(|d| d.remove_temp(orig_id))
+ && escaped
+ {
+ sz = before;
+ }
if sz != v.icon_size {
match v.inst {
Inst::Main => app.session.prefs.project_panel.view.icon_size = sz,
Inst::Tab(k) => app.ui.project_panel.tabs[k].icon_size = sz,
}
}
- if v.inst == Inst::Main && (resp.drag_stopped() || (resp.changed() && !resp.dragged())) {
+ if v.inst == Inst::Main && !escaped && (resp.drag_stopped() || (resp.changed() && !resp.dragged())) {
actions.push(("project.view.set".into(), json!({"iconSize": sz})));
}
x = sr.max.x + 6.0;
diff --git a/crates/ui-egui/src/panels/project_dialogs.rs b/crates/ui-egui/src/panels/project_dialogs.rs
index c16d3a6ef..582fb9850 100644
--- a/crates/ui-egui/src/panels/project_dialogs.rs
+++ b/crates/ui-egui/src/panels/project_dialogs.rs
@@ -15,6 +15,7 @@ fn push(app: &mut FilmcraftApp, id: &str, r: &egui::Response, label: &str) {
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.project_panel.dialog.clone() else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("project-dialog-before-drag"), &mut d);
let mut close = false;
let mut run: Option<(String, Value)> = None;
let title = match &d {
@@ -82,7 +83,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
}
}
});
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
close = true;
}
if let Some((cmd, p)) = run {
diff --git a/crates/ui-egui/src/panels/remix.rs b/crates/ui-egui/src/panels/remix.rs
index 459fcdd92..63307ec47 100644
--- a/crates/ui-egui/src/panels/remix.rs
+++ b/crates/ui-egui/src/panels/remix.rs
@@ -44,6 +44,7 @@ pub fn is_open(ctx: &egui::Context) -> bool {
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(Some(mut d)) = ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())) else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("remix-dialog-before-drag"), &mut d);
let mut close = false;
let mut apply = false;
let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
@@ -88,7 +89,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
close = true;
}
if apply {
diff --git a/crates/ui-egui/src/panels/sequence_settings.rs b/crates/ui-egui/src/panels/sequence_settings.rs
index d7fe5d025..fe9560790 100644
--- a/crates/ui-egui/src/panels/sequence_settings.rs
+++ b/crates/ui-egui/src/panels/sequence_settings.rs
@@ -475,6 +475,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
let audio_samples = app.session.project.settings.audio_display_samples;
let accent = app.tokens.accent;
let mut d = app.ui.sequence_settings.clone();
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("sequence-settings-before-drag"), &mut d);
let mut keep = true;
let mut apply = false;
let mut elems: Elems = Vec::new();
@@ -526,7 +527,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
keep = false;
}
if ctx.input(|i| i.key_pressed(egui::Key::Enter)) && !ctx.egui_wants_keyboard_input() {
diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs
index 336ba0970..d26a69146 100644
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@ -691,6 +691,7 @@ fn rows(app: &mut FilmcraftApp, ui: &mut Ui, d: &mut SettingsDraft, list: &[Row]
/// Draw the dialog; returns whether it stays open.
pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
let Some(mut d) = app.ui.settings.take() else { return false };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("settings-dialog-before-drag"), &mut d);
let t = app.tokens;
let mut close = false;
let mut apply = false;
@@ -781,7 +782,8 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
Err(e) => d.message = e.to_string(),
}
}
- if resp.should_close() || ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ // (the modal's own close also fires on Escape: not while a drag is being cancelled)
+ if (resp.should_close() && !ctx.input(|i| i.pointer.any_down())) || crate::widgets::escape_closes(ctx) {
close = true;
}
if !close {
diff --git a/crates/ui-egui/src/panels/text.rs b/crates/ui-egui/src/panels/text.rs
index 842000955..b6bc21552 100644
--- a/crates/ui-egui/src/panels/text.rs
+++ b/crates/ui-egui/src/panels/text.rs
@@ -414,7 +414,9 @@ fn style_strip(app: &mut FilmcraftApp, ui: &mut egui::Ui, r: Rect, track_idx: us
let mut size = st.size;
let resp = ui.add(egui::DragValue::new(&mut size).range(8.0..=200.0).speed(0.5).suffix(" px"));
app.auto.add("text.captions.style.size", resp.rect, "Caption size");
- if resp.drag_stopped() || (resp.changed() && !resp.dragged()) {
+ // a drag ended by Escape keeps the size it had (#580)
+ let escaped = resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape));
+ if !escaped && (resp.drag_stopped() || (resp.changed() && !resp.dragged())) {
actions.push(("captions.setStyle".into(), json!({"track": tr.id.0, "size": size})));
}
let mut col = Color32::from_rgba_unmultiplied(st.color[0], st.color[1], st.color[2], st.color[3]);
diff --git a/crates/ui-egui/src/panels/trim_monitor.rs b/crates/ui-egui/src/panels/trim_monitor.rs
index 2cb4838ed..ba65b9474 100644
--- a/crates/ui-egui/src/panels/trim_monitor.rs
+++ b/crates/ui-egui/src/panels/trim_monitor.rs
@@ -258,7 +258,8 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
if resp.drag_stopped() {
let total = ui.ctx().data_mut(|d| d.remove_temp::<f32>(egui::Id::new("trim-monitor-dx")).unwrap_or(0.0));
let n = (total * fpp).round() as i64;
- if n != 0 {
+ // egui ends a drag on Escape: that stop abandons it (#580)
+ if n != 0 && !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
drag_trim(app, which, n);
}
}
diff --git a/crates/ui-egui/src/panels/voiceover.rs b/crates/ui-egui/src/panels/voiceover.rs
index 292bc398f..0384ec290 100644
--- a/crates/ui-egui/src/panels/voiceover.rs
+++ b/crates/ui-egui/src/panels/voiceover.rs
@@ -231,6 +231,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
fn settings_dialog(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(Some(mut d)) = ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())) else { return };
+ crate::widgets::revert_drag_on_escape(ctx, egui::Id::new("voiceover-settings-before-drag"), &mut d);
let mut elems: Vec<(String, Rect, String)> = Vec::new();
let mut close = false;
let mut apply = false;
@@ -337,7 +338,7 @@ fn settings_dialog(app: &mut FilmcraftApp, ctx: &egui::Context) {
Err(error) => app.ui.status = error.to_string(),
}
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
close = true;
}
if apply {
diff --git a/crates/ui-egui/src/panels/workspaces.rs b/crates/ui-egui/src/panels/workspaces.rs
index fd7e8d697..2093f0860 100644
--- a/crates/ui-egui/src/panels/workspaces.rs
+++ b/crates/ui-egui/src/panels/workspaces.rs
@@ -172,7 +172,7 @@ pub fn dialogs(app: &mut FilmcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.workspace_dialog.clone() else { return };
let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
let mut push = |id: &str, r: &egui::Response, label: &str| elems.push((id.to_string(), r.rect, label.to_string()));
- let mut close = ctx.input(|i| i.key_pressed(egui::Key::Escape));
+ let mut close = crate::widgets::escape_closes(ctx);
let mut act: Option<(&str, Value)> = None;
let names = dock::names(&app.workspaces);
let changed: Vec<String> = app.workspaces.saved.iter().map(|s| s.name.clone()).collect();
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index d57b01ebe..ad899ec46 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -163,6 +163,35 @@ pub fn timecode_field(
out
}
+/// Escape closes a dialog or popup only when no mouse button is held: with one held it cancels the
+/// drag in progress instead (#580).
+pub fn escape_closes(ctx: &egui::Context) -> bool {
+ ctx.input(|i| i.key_pressed(egui::Key::Escape) && !i.pointer.any_down())
+}
+
+/// Keep a dialog's `draft` as a mouse press begins; Escape while the button is held puts it back,
+/// so a dragged number, slider or color returns to its value (#580). Call before drawing the
+/// dialog's widgets, and close the dialog with [`escape_closes`] so the same Escape keeps it open.
+/// The draft is put back on every frame until the button comes up: on the Escape frame itself a
+/// color picker's popup, drawn after this call, still sets its color from the pointer.
+pub fn revert_drag_on_escape<T: Clone + Send + Sync + 'static>(ctx: &egui::Context, id: egui::Id, draft: &mut T) {
+ let (pressed, down, escape) = ctx.input(|i| (i.pointer.any_pressed(), i.pointer.any_down(), i.key_pressed(egui::Key::Escape)));
+ if pressed && down {
+ ctx.data_mut(|d| d.insert_temp(id, (draft.clone(), false)));
+ return;
+ }
+ // (the draft when the press began, whether Escape cancelled the drag)
+ let Some((before, cancelled)) = ctx.data(|d| d.get_temp::<(T, bool)>(id)) else { return };
+ if escape || cancelled {
+ *draft = before.clone();
+ }
+ if !down {
+ ctx.data_mut(|d| d.remove::<(T, bool)>(id));
+ } else if escape && !cancelled {
+ ctx.data_mut(|d| d.insert_temp(id, (before, true)));
+ }
+}
+
/// A twirl-down section header (Effect Controls / Lumetri style). Returns open state.
pub fn section_header(ui: &mut Ui, id: egui::Id, title: &str, open: bool, t: &Tokens, bold: bool) -> (Response, bool) {
let w = ui.available_width();
diff --git a/crates/ui-egui/tests/clip_dialogs_ui.rs b/crates/ui-egui/tests/clip_dialogs_ui.rs
index b60493718..78f8acd47 100644
--- a/crates/ui-egui/tests/clip_dialogs_ui.rs
+++ b/crates/ui-egui/tests/clip_dialogs_ui.rs
@@ -341,3 +341,47 @@ fn quit_save_on_a_new_project_uses_the_save_dialog_and_scripted_quit_does_not_as
d.ok("app.quit", json!({}));
assert!(d.app().quit_confirmed);
}
+
+/// #580: Escape while dragging a value in a dialog puts the value back and keeps the dialog open;
+/// Escape with no drag still closes it.
+#[test]
+fn escape_mid_drag_reverts_the_field_and_keeps_the_dialog() {
+ let mut d = Driver::new();
+ let c = d.v1(0);
+ d.exec("timeline.select", json!({"clips": [c.id.0]}));
+ d.menu("clip.speedDuration");
+ let els = d.ok("ui.elements", json!({"prefix": "speedDuration.speed"}));
+ let r: Vec<f32> = els.as_array().unwrap().iter().find(|e| e["id"] == "speedDuration.speed").expect("speed field")["rect"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|v| v.as_f64().unwrap() as f32)
+ .collect();
+ let from = egui::pos2(r[0] + r[2] / 2.0, r[1] + r[3] / 2.0);
+ let speed = |d: &mut Driver| d.app().ui.clip_dialog.as_ref().map(|g| g.params["speed"].clone());
+ let drag = |d: &mut Driver, escape: bool| {
+ let mut send = |e: egui::Event| {
+ d.harness.input_mut().events.push(e);
+ d.frames(1);
+ };
+ let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
+ send(egui::Event::PointerMoved(from));
+ send(button(from, true));
+ for k in 1..=10 {
+ send(egui::Event::PointerMoved(from + egui::vec2(4.0 * k as f32, 0.0)));
+ if escape && k == 5 {
+ send(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
+ }
+ }
+ send(button(from + egui::vec2(40.0, 0.0), false));
+ d.frames(3);
+ };
+ drag(&mut d, true);
+ assert_eq!(speed(&mut d), Some(json!(100.0)), "the speed it had before the drag, and the dialog is still open");
+ drag(&mut d, false);
+ assert_ne!(speed(&mut d), Some(json!(100.0)), "without Escape the same drag changes the speed");
+ d.ok("ui.key", json!({"key": "Escape"}));
+ d.frames(2);
+ assert!(d.app().ui.clip_dialog.is_none(), "Escape with no drag closes the dialog");
+ assert_eq!(d.v1(0).speed, 1.0, "and applies nothing");
+}
diff --git a/crates/ui-egui/tests/escape_drag_ui.rs b/crates/ui-egui/tests/escape_drag_ui.rs
index 51c74b6f5..bfe4e80f7 100644
--- a/crates/ui-egui/tests/escape_drag_ui.rs
+++ b/crates/ui-egui/tests/escape_drag_ui.rs
@@ -158,6 +158,81 @@ fn escape_puts_a_freeform_card_back_and_the_next_drag_works() {
assert!(meta(&d), "after a cancel the next drag places the card");
}
+#[test]
+fn escape_takes_back_a_value_drag_in_properties() {
+ let mut d = Driver::demo();
+ let clip = d.ok("engine.execute", json!({"command": "graphics.newText", "params": {"text": "Hi"}}))["clip"].as_u64().expect("graphic clip");
+ d.ok("engine.execute", json!({"command": "timeline.select", "params": {"clips": [clip]}}));
+ d.ok("ui.panel.show", json!({"panel": "Properties"}));
+ d.frames(4);
+ let from = centre(d.rect("graphics.prop.scale"));
+ let to = from + egui::vec2(40.0, 0.0);
+ let (before, undo) = (d.project(), d.undo_len());
+ d.drag(from, to, true);
+ assert_eq!(d.project(), before, "the scale is back to what it was");
+ assert_eq!(d.undo_len(), undo, "nothing to undo");
+ assert!(d.harness.state().session.history.redo.is_empty(), "nothing to redo");
+ d.drag(from, to, false);
+ assert_ne!(d.project(), before, "without Escape the same drag changes the scale");
+ assert_eq!(d.undo_len(), undo + 1, "as one undo step");
+}
+
+/// The color picker applies colors as you drag in it; Escape takes all of them back.
+#[test]
+fn escape_takes_back_a_color_picker_drag() {
+ let mut d = Driver::demo();
+ let clip = d.ok("engine.execute", json!({"command": "graphics.newText", "params": {"text": "Hi"}}))["clip"].as_u64().expect("graphic clip");
+ d.ok("engine.execute", json!({"command": "timeline.select", "params": {"clips": [clip]}}));
+ d.ok("ui.panel.show", json!({"panel": "Properties"}));
+ d.ok("ui.set", json!({"focused": "Properties"}));
+ d.ok("ui.menu.invoke", json!({"id": "window.maximizeFrame"}));
+ d.frames(4);
+ // the picker's popup, and in it the saturation / value square under the RGB row and swatch
+ // scroll the Fill color up into the window, with room under it for the picker
+ for _ in 0..10 {
+ if d.rect("graphics.prop.fill_color")[1] < 500.0 {
+ break;
+ }
+ d.ok("ui.scroll", json!({"id": "graphics.prop.scale", "dy": -200.0}));
+ }
+ let picker = |d: &mut Driver| {
+ d.ok("ui.click", json!({"id": "graphics.prop.fill_color"}));
+ let popup = d.harness.ctx.memory(|m| {
+ m.areas()
+ .visible_layer_ids()
+ .into_iter()
+ .filter(|l| l.order == egui::Order::Foreground)
+ .filter_map(|l| m.area_rect(l.id))
+ .max_by(|a, b| a.area().total_cmp(&b.area()))
+ });
+ let r = popup.expect("the color picker opened");
+ (r.min + egui::vec2(30.0, 90.0), r.min + egui::vec2(70.0, 120.0))
+ };
+ let (before, undo) = (d.project(), d.undo_len());
+ let (from, to) = picker(&mut d);
+ d.drag(from, to, true);
+ assert_eq!(d.project(), before, "the fill color is back to what it was");
+ assert_eq!(d.undo_len(), undo, "nothing to undo");
+ d.ok("ui.key", json!({"key": "Escape"}));
+ let (from, to) = picker(&mut d);
+ d.drag(from, to, false);
+ assert_ne!(d.project(), before, "without Escape the same drag picks a color");
+}
+
+#[test]
+fn escape_puts_a_thumbnail_size_slider_back() {
+ let mut d = Driver::demo();
+ d.footage_in("icon");
+ let size = |d: &Driver| d.harness.state().session.prefs.project_panel.view.icon_size;
+ let start = size(&d);
+ let r = d.rect("project.iconSize");
+ let (from, to) = (egui::pos2(r[0] + r[2] * 0.3, r[1] + r[3] / 2.0), egui::pos2(r[0] + r[2] * 0.9, r[1] + r[3] / 2.0));
+ d.drag(from, to, true);
+ assert_eq!(size(&d), start, "the slider went back");
+ d.drag(from, to, false);
+ assert_ne!(size(&d), start, "without Escape the same drag resizes");
+}
+
#[test]
fn escape_cancels_dragging_an_effect_onto_a_clip() {
let mut d = Driver::demo();
diff --git a/crates/ui-egui/tests/settings_ui.rs b/crates/ui-egui/tests/settings_ui.rs
index eca13d504..ad4c6a1b3 100644
--- a/crates/ui-egui/tests/settings_ui.rs
+++ b/crates/ui-egui/tests/settings_ui.rs
@@ -200,6 +200,96 @@ fn checkbox_edits_apply_on_ok_and_not_on_cancel() {
assert_eq!(d.pref("timeline.snapPlayhead"), false, "on by default (as in Premiere), the click turns it off");
}
+/// #580: Escape while dragging a number in Settings puts it back and keeps the dialog open (the
+/// modal's own Escape close included); Escape with no drag still cancels the dialog.
+#[test]
+fn escape_mid_drag_reverts_a_setting_and_keeps_the_dialog() {
+ let mut d = Driver::demo();
+ d.menu("app.settings.playback");
+ let els = d.ok("ui.elements", json!({"prefix": "settings.playback.stepManyFrames"}));
+ let r: Vec<f32> = els.as_array().unwrap().iter().find(|e| e["id"] == "settings.playback.stepManyFrames").expect("number field")["rect"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|v| v.as_f64().unwrap() as f32)
+ .collect();
+ let from = egui::pos2(r[0] + r[2] / 2.0, r[1] + r[3] / 2.0);
+ let drag = |d: &mut Driver, escape: bool| {
+ let mut send = |e: egui::Event| {
+ d.harness.input_mut().events.push(e);
+ d.frames(1);
+ };
+ let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
+ send(egui::Event::PointerMoved(from));
+ send(button(from, true));
+ for k in 1..=10 {
+ send(egui::Event::PointerMoved(from + egui::vec2(6.0 * k as f32, 0.0)));
+ if escape && k == 5 {
+ send(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
+ }
+ }
+ send(button(from + egui::vec2(60.0, 0.0), false));
+ d.frames(3);
+ };
+ let before = d.draft();
+ drag(&mut d, true);
+ assert_eq!(d.draft(), before, "the value it had before the drag, and the dialog is still open");
+ drag(&mut d, false);
+ assert_ne!(d.draft(), before, "without Escape the same drag changes it");
+ d.ok("ui.key", json!({"key": "Escape"}));
+ d.frames(2);
+ assert_eq!(d.draft(), Value::Null, "Escape with no drag closes the dialog");
+}
+
+/// #580: the color pickers in Settings take back a drag on Escape too, as everywhere else.
+#[test]
+fn escape_mid_drag_reverts_a_settings_color() {
+ let mut d = Driver::demo();
+ d.menu("app.settings.appearance");
+ // the areas on top: the Settings modal, and the picker's popup over it when it is open
+ let on_top = |d: &Driver| {
+ d.harness.ctx.memory(|m| {
+ let mut v: Vec<egui::Rect> =
+ m.areas().visible_layer_ids().into_iter().filter(|l| l.order == egui::Order::Foreground).filter_map(|l| m.area_rect(l.id)).collect();
+ v.sort_by(|a, b| a.area().total_cmp(&b.area()));
+ v
+ })
+ };
+ let picker = |d: &mut Driver| {
+ if on_top(d).len() < 2 {
+ d.ok("ui.click", json!({"id": "settings.appearance.highlightColor"}));
+ }
+ let r = *on_top(d).first().expect("the color picker opened");
+ (r.min + egui::vec2(30.0, 90.0), r.min + egui::vec2(70.0, 120.0))
+ };
+ let drag = |d: &mut Driver, from: egui::Pos2, to: egui::Pos2, escape: bool| {
+ let mut send = |e: egui::Event| {
+ d.harness.input_mut().events.push(e);
+ d.frames(1);
+ };
+ let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
+ send(egui::Event::PointerMoved(from));
+ send(button(from, true));
+ for k in 1..=10 {
+ send(egui::Event::PointerMoved(from.lerp(to, k as f32 / 10.0)));
+ if escape && k == 5 {
+ send(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
+ }
+ }
+ send(button(to, false));
+ d.frames(3);
+ };
+ let color = |d: &mut Driver| d.draft()["values"]["appearance"]["highlightColor"].clone();
+ let before = color(&mut d);
+ let (from, to) = picker(&mut d);
+ drag(&mut d, from, to, true);
+ assert_eq!(color(&mut d), before, "the highlight color it had before the drag");
+ assert_ne!(d.draft(), Value::Null, "the dialog is still open");
+ let (from, to) = picker(&mut d);
+ drag(&mut d, from, to, false);
+ assert_ne!(color(&mut d), before, "without Escape the same drag picks a color");
+}
+
#[test]
fn dropdowns_numbers_and_reset() {
let mut d = Driver::demo();