Skip to content

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

History: the panel menu deletes redoable actions and clears the history (#3075)

.CooCoob206b1332d4f
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index e01fa8491..079f6c6db 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -112,6 +112,9 @@ fn can_undo(s: &Session) -> std::result::Result<(), String> {
fn can_redo(s: &Session) -> std::result::Result<(), String> {
if s.history.can_redo() { Ok(()) } else { Err("nothing to redo".into()) }
}
+fn has_history(s: &Session) -> std::result::Result<(), String> {
+ if s.history.can_undo() || s.history.can_redo() { Ok(()) } else { Err("the history is empty".into()) }
+}
fn has_in_out(s: &Session) -> std::result::Result<(), String> {
let seq = s.active_sequence().ok_or("no sequence is open")?;
if seq.mark_in.is_some() || seq.mark_out.is_some() { Ok(()) } else { Err("mark an In or Out point first".into()) }
@@ -1629,6 +1632,9 @@ fn build() -> Vec<CommandSpec> {
// ================= Edit =================
cmd!("edit.undo", "Undo", ["Edit"], Some("Cmd+Z"), "{}", can_undo, |s, _| Ok(json!({"undone": s.undo()}))),
cmd!("edit.redo", "Redo", ["Edit"], Some("Cmd+Shift+Z"), "{}", can_redo, |s, _| Ok(json!({"redone": s.redo()}))),
+ // the History panel menu; neither one changes the project or its unsaved state
+ cmd!("history.deleteRedoable", "Delete Redoable Actions", [], None, "{}", can_redo, |s, _| Ok(json!({"deleted": s.history.delete_redoable()}))),
+ cmd!("history.clear", "Clear History", [], None, "{}", has_history, |s, _| Ok(json!({"deleted": s.history.clear()}))),
cmd!("edit.cut", "Cut", ["Edit"], Some("Cmd+X"), "{}", has_clips_or_captions, |s, _| {
if s.state.selection.is_empty() {
crate::captions::copy(s);
diff --git a/crates/engine/src/history_tests.rs b/crates/engine/src/history_tests.rs
new file mode 100644
index 000000000..1f5b26191
--- /dev/null
+++ b/crates/engine/src/history_tests.rs
@@ -0,0 +1,77 @@
+//! The History panel menu: `history.deleteRedoable` (Delete Redoable Actions) forgets the steps
+//! Redo would bring back, and `history.clear` (Clear History) forgets every step. Neither one
+//! changes the project or its unsaved state.
+
+use serde_json::json;
+
+use crate::Session;
+
+/// The demo project with three labeled edits, then two of them undone.
+fn three_edits_two_undone() -> Session {
+ let mut s = Session::default();
+ s.execute("file.openDemoProject", json!({})).unwrap();
+ for name in ["A", "B", "C"] {
+ s.execute("file.newBin", json!({"name": name})).unwrap();
+ }
+ s.execute("edit.undo", json!({})).unwrap();
+ s.execute("edit.undo", json!({})).unwrap();
+ s
+}
+
+#[test]
+fn delete_redoable_actions_forgets_the_undone_steps_only() {
+ let mut s = three_edits_two_undone();
+ let before = s.execute("history.list", json!({})).unwrap();
+ assert_eq!(before["redo"].as_array().unwrap().len(), 2, "{before}");
+ let project = s.project.clone();
+ let dirty = s.is_dirty();
+
+ let r = s.execute("history.deleteRedoable", json!({})).unwrap();
+ assert_eq!(r, json!({"deleted": 2}));
+ let after = s.execute("history.list", json!({})).unwrap();
+ assert_eq!(after["undo"], before["undo"], "the steps Undo takes back stay");
+ assert_eq!(after["redo"], json!([]));
+ assert_eq!(*s.project, *project, "the project does not change");
+ assert_eq!(s.is_dirty(), dirty);
+ assert!(s.execute("edit.redo", json!({})).is_err(), "nothing is left to redo");
+ // Undo still takes back the step before
+ s.execute("edit.undo", json!({})).unwrap();
+ // with nothing to redo the command is disabled
+ s.history.redo.clear();
+ assert!(s.execute("history.deleteRedoable", json!({})).is_err());
+}
+
+#[test]
+fn clear_history_forgets_every_step_and_keeps_the_project() {
+ let mut s = three_edits_two_undone();
+ let undo = s.history.undo.len();
+ assert!(undo > 0);
+ let project = s.project.clone();
+ let dirty = s.is_dirty();
+
+ let r = s.execute("history.clear", json!({})).unwrap();
+ assert_eq!(r, json!({"deleted": undo + 2}));
+ assert_eq!(s.execute("history.list", json!({})).unwrap(), json!({"undo": [], "redo": []}));
+ assert_eq!(*s.project, *project, "the project does not change");
+ assert_eq!(s.is_dirty(), dirty);
+ assert!(s.execute("edit.undo", json!({})).is_err());
+ assert!(s.execute("history.clear", json!({})).is_err(), "an empty history has nothing to clear");
+
+ // a new edit starts a new history and can be undone
+ s.execute("file.newBin", json!({"name": "D"})).unwrap();
+ assert_eq!(s.history.undo.len(), 1);
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(*s.project, *project);
+}
+
+#[test]
+fn history_commands_ignore_unexpected_parameters() {
+ for p in [json!(null), json!([1, 2]), json!({"deleted": -1}), json!("x")] {
+ let mut s = three_edits_two_undone();
+ let undo = s.history.undo.len();
+ assert_eq!(s.execute("history.deleteRedoable", p.clone()).unwrap(), json!({"deleted": 2}), "{p}");
+ assert_eq!(s.history.undo.len(), undo, "{p}");
+ assert_eq!(s.execute("history.clear", p.clone()).unwrap(), json!({"deleted": undo}), "{p}");
+ assert_eq!(s.execute("history.list", json!({})).unwrap(), json!({"undo": [], "redo": []}), "{p}");
+ }
+}
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index dd2680bb4..f711ad190 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -242,6 +242,22 @@ impl History {
pub fn can_redo(&self) -> bool {
!self.redo.is_empty()
}
+ /// The History panel's Delete Redoable Actions: removes every step that Redo would bring
+ /// back. The project and the undo steps stay as they are. Returns how many steps were removed.
+ pub fn delete_redoable(&mut self) -> usize {
+ let n = self.redo.len();
+ self.redo.clear();
+ n
+ }
+ /// The History panel's Clear History: removes every undo and redo step. The project stays as
+ /// it is. Returns how many steps were removed.
+ pub fn clear(&mut self) -> usize {
+ let n = self.undo.len() + self.redo.len();
+ self.undo.clear();
+ self.redo.clear();
+ self.merge_key = None;
+ n
+ }
}
/// Source patching / track targeting (the track header "V1/A1" source buttons + target toggles).
@@ -1265,6 +1281,8 @@ mod file_tests;
#[cfg(test)]
mod gap_selection_tests;
#[cfg(test)]
+mod history_tests;
+#[cfg(test)]
mod image_sequence_tests;
#[cfg(test)]
mod individual_selection_tests;
diff --git a/crates/engine/src/shortcut_presets.rs b/crates/engine/src/shortcut_presets.rs
index 7e105e509..14bd2bf2a 100644
--- a/crates/engine/src/shortcut_presets.rs
+++ b/crates/engine/src/shortcut_presets.rs
@@ -264,6 +264,7 @@ pub const PREMIERE: &[Entry] = &[
("source.open", "Shift+O", "Project"),
("edit.undo", "Left", "History"),
("edit.redo", "Right", "History"),
+ ("history.deleteRedoable", "Backspace", "History"),
];
/// Premiere's panel-scoped default keys for the keyboard-only commands (M3.12). FilmCraft Default
diff --git a/crates/engine/src/shortcuts_tests.rs b/crates/engine/src/shortcuts_tests.rs
index c6beec578..4aeb6e824 100644
--- a/crates/engine/src/shortcuts_tests.rs
+++ b/crates/engine/src/shortcuts_tests.rs
@@ -288,7 +288,7 @@ fn list_searches_labels_and_keys() {
let v = s.execute("shortcuts.list", json!({"query": "cmd+k", "platform": "windows"})).unwrap();
assert!(v.as_array().unwrap().iter().any(|c| c["id"] == "sequence.addEdit"), "{v}");
let v = s.execute("shortcuts.list", json!({"panel": "History", "assigned": true})).unwrap();
- assert_eq!(v.as_array().unwrap().len(), 2, "{v}");
+ assert_eq!(v.as_array().unwrap().len(), 3, "{v}");
}
#[test]
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 214499151..19fbf457c 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -169,6 +169,9 @@
Hide All Caption Tracks Ocultar todas las pistas de subtítulos
High Quality Playback Reproducción de alta calidad
History Historial
+ Delete Redoable Actions Eliminar acciones que se pueden rehacer
+ Clear History Borrar historial
+ Delete the dimmed actions after the current state? They cannot be redone. ¿Eliminar las acciones atenuadas posteriores al estado actual? No se podrán rehacer.
Import From Importar desde
Import Image Sequence… Importar secuencia de imágenes…
Import from Media Browser Importar desde el navegador de medios
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 8446dac2b..fac3d1d9d 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -171,6 +171,9 @@
Hide All Caption Tracks すべてのキャプショントラックを非表示
High Quality Playback 高画質再生
History 履歴
+ Delete Redoable Actions やり直し可能な操作を削除
+ Clear History 履歴を消去
+ Delete the dimmed actions after the current state? They cannot be redone. 現在の状態より後の淡色表示の操作を削除しますか? 削除した操作はやり直せません。
Import From 読み込み元
Import Image Sequence… 連番画像を読み込み…
Import from Media Browser メディアブラウザーから読み込み
diff --git a/crates/ui-egui/src/i18n/zh-cn.tsv b/crates/ui-egui/src/i18n/zh-cn.tsv
index 647661bad..262632a97 100644
--- a/crates/ui-egui/src/i18n/zh-cn.tsv
+++ b/crates/ui-egui/src/i18n/zh-cn.tsv
@@ -164,6 +164,9 @@
Hide All Caption Tracks 隐藏所有字幕轨道
High Quality Playback 高质量播放
History 历史记录
+ Delete Redoable Actions 删除可重做的操作
+ Clear History 清除历史记录
+ Delete the dimmed actions after the current state? They cannot be redone. 删除当前状态之后显示为灰色的操作?删除后将无法重做。
Import From 导入来源
Import Image Sequence… 导入图像序列…
Import from Media Browser 从媒体浏览器导入
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index d4742ff59..2ee0a8e0a 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -287,6 +287,12 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, mut params:
if let Some(r) = crate::panels::clip_dialogs::route(app, id, &params) {
return r;
}
+ if let Some(r) = crate::panels::misc::route_history(app, ctx, id, &params) {
+ if let Err(e) = &r {
+ app.ui.status = e.clone();
+ }
+ return r;
+ }
if let Some(r) = crate::panels::settings::route(app, id) {
return r;
}
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index 8bc23dbc3..b8d738aee 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -23,6 +23,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
crate::panels::frame_export::show(app, ctx);
crate::panels::project_dialogs::show(app, ctx);
crate::panels::media_browser::dialogs(app, ctx);
+ crate::panels::misc::history_dialogs(app, ctx);
let Some(d) = app.dialog else { return };
if let Some(still_open) = crate::panels::file_dialogs::show(app, ctx, d) {
if !still_open && app.dialog == Some(d) {
diff --git a/crates/ui-egui/src/panels/misc.rs b/crates/ui-egui/src/panels/misc.rs
index f5bc5f1e9..2196c1c81 100644
--- a/crates/ui-egui/src/panels/misc.rs
+++ b/crates/ui-egui/src/panels/misc.rs
@@ -50,6 +50,76 @@ pub fn history(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
}
+/// Egui memory key of the open Delete Redoable Actions confirmation.
+const CONFIRM_DELETE_REDOABLE: &str = "history-delete-redoable";
+
+/// The History panel's ≡ menu: Delete Redoable Actions and Clear History (automation ids
+/// `panel.menu.History.deleteRedoable` and `panel.menu.History.clear`). Returns true to close it.
+pub fn history_panel_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui) -> bool {
+ let ctx = ui.ctx().clone();
+ let mut close = false;
+ for (id, label, command) in [("deleteRedoable", tl!("Delete Redoable Actions"), "history.deleteRedoable"), ("clear", tl!("Clear History"), "history.clear")]
+ {
+ let r = ui.add_enabled(app.session.is_enabled(command), egui::Button::new(label));
+ app.auto.add_response(&format!("panel.menu.History.{id}"), &r, label);
+ if r.clicked() {
+ if let Err(e) = crate::menus::invoke(app, &ctx, command, serde_json::json!({})) {
+ app.ui.status = e;
+ }
+ close = true;
+ }
+ }
+ close
+}
+
+/// Delete Redoable Actions from the panel menu or a key (no parameters) asks for OK first, as in
+/// Premiere. Returns None for other ids, and for calls with parameters, which run the command.
+pub fn route_history(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: &serde_json::Value) -> Option<Result<serde_json::Value, String>> {
+ if id != "history.deleteRedoable" || !params.as_object().is_none_or(|m| m.is_empty()) {
+ return None;
+ }
+ if !app.session.history.can_redo() {
+ return Some(Err("nothing to redo".into()));
+ }
+ ctx.data_mut(|d| d.insert_temp(egui::Id::new(CONFIRM_DELETE_REDOABLE), true));
+ Some(Ok(serde_json::json!({"dialog": "deleteRedoable"})))
+}
+
+/// The Delete Redoable Actions confirmation (automation ids `history.deleteRedoable.cancel` and
+/// `history.deleteRedoable.ok`). It closes by itself when nothing is left to redo.
+pub fn history_dialogs(app: &mut FilmcraftApp, ctx: &egui::Context) {
+ let key = egui::Id::new(CONFIRM_DELETE_REDOABLE);
+ if !ctx.data(|d| d.get_temp::<bool>(key)).unwrap_or(false) {
+ return;
+ }
+ let mut close = !app.session.history.can_redo();
+ egui::Window::new(tl!("Delete Redoable Actions"))
+ .id(key.with("window"))
+ .collapsible(false)
+ .resizable(false)
+ .pivot(Align2::CENTER_CENTER)
+ .default_pos(crate::widgets::dialog_center(ctx))
+ .show(ctx, |ui| {
+ ui.label(tl!("Delete the dimmed actions after the current state? They cannot be redone."));
+ ui.horizontal(|ui| {
+ let r = ui.button(tl!("Cancel"));
+ app.auto.add("history.deleteRedoable.cancel", r.rect, "Cancel");
+ close |= r.clicked();
+ let r = ui.button(tl!("OK"));
+ app.auto.add("history.deleteRedoable.ok", r.rect, "OK");
+ if r.clicked() {
+ if let Err(e) = app.session.execute("history.deleteRedoable", serde_json::json!({})) {
+ app.ui.status = e.to_string();
+ }
+ close = true;
+ }
+ });
+ });
+ if close || crate::widgets::escape_closes(ctx) {
+ ctx.data_mut(|d| d.remove::<bool>(key));
+ }
+}
+
/// The marker colours of the Markers panel filter (each chip stands for the labels that share its
/// marker colour).
pub const MARKER_FILTER: [filmcraft_project::Label; 7] = {
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index 0f21158fc..532f8db17 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -352,6 +352,10 @@ pub fn panel_menu_popup(app: &mut FilmcraftApp, ui: &mut egui::Ui) {
ui.separator();
close |= monitor::source_panel_menu(app, ui);
}
+ if p == PanelKind::History {
+ ui.separator();
+ close |= misc::history_panel_menu(app, ui);
+ }
});
app.auto.add("panel.menu.scroll", scroll.inner_rect, "Panel menu");
});
diff --git a/crates/ui-egui/tests/it/panels_ui.rs b/crates/ui-egui/tests/it/panels_ui.rs
index 150f4d0bf..768bfd785 100644
--- a/crates/ui-egui/tests/it/panels_ui.rs
+++ b/crates/ui-egui/tests/it/panels_ui.rs
@@ -210,6 +210,48 @@ fn panel_menu_maximize_restores_and_an_empty_dock_reopens() {
assert!(d.has("panel.tab.Program") && d.has("panel.tab.Timeline"));
}
+/// The History panel menu: Delete Redoable Actions asks for OK and then forgets the dimmed steps
+/// (Backspace in the History panel asks the same), and Clear History forgets every step. The
+/// project stays as it is.
+#[test]
+fn history_panel_menu_deletes_redoable_actions_and_clears_the_history() {
+ let mut d = Driver::demo();
+ for name in ["A", "B", "C"] {
+ d.exec("file.newBin", json!({"name": name}));
+ }
+ d.exec("edit.undo", json!({}));
+ d.exec("edit.undo", json!({}));
+ d.ok("ui.menu.invoke", json!({"id": "window.panel.History"}));
+ d.frames(3);
+ let redo = |d: &mut Driver| d.exec("history.list", json!({}))["redo"].as_array().unwrap().len();
+ assert_eq!(redo(&mut d), 2);
+ let project = d.app().session.project.clone();
+
+ d.click("panel.menu.History");
+ assert_eq!(d.label("panel.menu.History.deleteRedoable"), "Delete Redoable Actions");
+ assert_eq!(d.label("panel.menu.History.clear"), "Clear History");
+ d.click("panel.menu.History.deleteRedoable");
+ assert!(d.has("history.deleteRedoable.ok"), "Delete Redoable Actions asks first");
+ assert_eq!(redo(&mut d), 2, "nothing is deleted before OK");
+ d.click("history.deleteRedoable.cancel");
+ assert!(!d.has("history.deleteRedoable.ok"));
+ assert_eq!(redo(&mut d), 2, "Cancel keeps the steps");
+
+ d.ok("ui.key", json!({"key": "Backspace"}));
+ d.frames(2);
+ assert!(d.has("history.deleteRedoable.ok"), "Backspace in the History panel asks too");
+ d.click("history.deleteRedoable.ok");
+ assert!(!d.has("history.deleteRedoable.ok"));
+ assert_eq!(redo(&mut d), 0);
+ assert_eq!(*d.app().session.project, *project, "the project does not change");
+
+ d.click("panel.menu.History");
+ d.click("panel.menu.History.clear");
+ assert_eq!(d.exec("history.list", json!({})), json!({"undo": [], "redo": []}));
+ assert_eq!(*d.app().session.project, *project, "the project does not change");
+ assert!(!d.app().session.is_enabled("history.clear"), "an empty history has nothing to clear");
+}
+
/// The wheel over a tab strip switches that group's tab: down = next, up = previous, one tab per
/// notch, smaller trackpad steps adding up to a notch, stopping at the ends. Over the panel's
/// content the wheel leaves the tabs alone.
diff --git a/docs/keyboard.md b/docs/keyboard.md
index a9eade807..4ca06cfa8 100644
--- a/docs/keyboard.md
+++ b/docs/keyboard.md
@@ -30,6 +30,7 @@ Premiere has these as keys only (most are not in a menu). Modules: `filmcraft_en
| Panels | Maximize or Restore Active Frame / Frame Under Cursor, Select Next/Previous Panel, Toggle Source/Program Monitor Focus, Workspaces 7–9 | Shift+`, `, Ctrl+Shift+. / ,, Alt+Shift+7/8/9 |
| Audio | Increase/Decrease Clip Volume (1 dB) and …Many (Settings ▸ Audio ▸ Large Volume Adjustment), Nudge Volume ±1/±3 dB, Toggle Audio During Scrubbing | ] / [, Shift+] / Shift+[, Shift+S |
| Graphics | Increase/Decrease Font Size and Leading by One/Five Units, Left/Center/Right align text, Begin Text Editing, Nudge Selected Object by one/five (graphic layers, else Motion position) | Cmd+Alt+(Shift+)Left/Right, Alt+(Shift+)Up/Down, Cmd+Shift+L/C/R, Cmd+Alt+', Cmd+(Shift+)arrows (Program, Properties) |
+| History panel | Delete (Delete Redoable Actions, which asks for OK first) | Backspace |
| Project panel | List/Icon/Toggle View, Hover Scrub, Thumbnail Size Next/Previous (and = / -), Move/Extend Selection, Mark In / Out of the hover-scrubbed clip | Cmd+PageUp/PageDown, Shift+\, Shift+H, Shift+] / Shift+[, arrows, Home/End, PageUp/PageDown, I / O |
| Text panel | Navigate/Select to Previous/Next Word and Line, Start/End of Segment, Delete (lift), Ripple Delete (extract), Show Program Transcript, Merge/Split Segments | arrows, Shift+arrows, Home/End, Shift+Home, Cmd+Shift+Down, Alt+Backspace, Backspace, Shift+X, Alt+M / Alt+S |
| Other | Help (F1), Quit (Cmd+Q), Media Browser ▸ Open In Source Monitor (imports the file first), Send to Media Encoder (= Send to Export Queue, Alt+Shift+M), Metadata panel Play/Loop | |
@@ -55,7 +56,6 @@ Frame has no default key; the Premiere preset moves Shift+E to Export Frame and
| Audio Track Mixer: Show/Hide Tracks… (⌥⌘T), Meter Input(s) Only (⌃⇧I) | The mixer has no track visibility dialog and no input metering (no hardware input recording). |
| Effect Controls: Remove Selected Effect (Delete), Loop During Audio-Only Playback (⌘L) | Effect Controls has no effect selection state and no audio-only playback mode; effects are removed from their context menu or `effects.remove`. |
| Effects panel: New Custom Bin (⌘/), Delete Custom Item (Delete) | The Effects panel has no custom bins (effect presets live in the Presets bin). |
-| History panel: Delete (Delete) | History states cannot be selected and deleted individually. |
| Media Browser: Select Directory List / Select Media List (⇧← / ⇧→) | The directory tree and media list take no separate keyboard focus. |
| Project panel: Delete Selection with Options (⌘Delete) | Needs the "delete instances in sequences" dialog; plain Clear (Backspace) deletes. |
| Project panel: Next/Previous Column Field, Next/Previous Row Field (Tab, ⇧Tab, Return, ⇧Return) | The list view has no inline-editable metadata cells. |