diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 2a74bf9..0f11820 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -41,6 +41,12 @@ const MAGIC: &str = "edith-keys 1"; #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum ActionId { Play, + StepBack, + StepForward, + JumpBack, + JumpForward, + GoStart, + GoEnd, Export, Save, Copy, @@ -68,8 +74,14 @@ pub enum ActionId { impl ActionId { /// Display order everywhere -- the editor lists them in it and /// [`Keymap::defaults`] binds them in it. - pub const ALL: [ActionId; 23] = [ + pub const ALL: [ActionId; 29] = [ ActionId::Play, + ActionId::StepBack, + ActionId::StepForward, + ActionId::JumpBack, + ActionId::JumpForward, + ActionId::GoStart, + ActionId::GoEnd, ActionId::Export, ActionId::Save, ActionId::Copy, @@ -98,6 +110,12 @@ impl ActionId { pub fn label(self) -> &'static str { match self { ActionId::Play => "Play / Pause", + ActionId::StepBack => "One frame back", + ActionId::StepForward => "One frame forward", + ActionId::JumpBack => "One second back", + ActionId::JumpForward => "One second forward", + ActionId::GoStart => "Go to the start", + ActionId::GoEnd => "Go to the last frame", ActionId::Export => "Export", ActionId::Save => "Save", ActionId::Copy => "Copy", @@ -128,6 +146,12 @@ impl ActionId { fn name(self) -> &'static str { match self { ActionId::Play => "play", + ActionId::StepBack => "step-back", + ActionId::StepForward => "step-forward", + ActionId::JumpBack => "jump-back", + ActionId::JumpForward => "jump-forward", + ActionId::GoStart => "go-start", + ActionId::GoEnd => "go-end", ActionId::Export => "export", ActionId::Save => "save", ActionId::Copy => "copy", @@ -162,7 +186,13 @@ impl ActionId { /// forget. pub fn category(self) -> Category { match self { - ActionId::Play => Category::Playback, + ActionId::Play + | ActionId::StepBack + | ActionId::StepForward + | ActionId::JumpBack + | ActionId::JumpForward + | ActionId::GoStart + | ActionId::GoEnd => Category::Playback, ActionId::Copy | ActionId::Paste | ActionId::Select @@ -403,6 +433,18 @@ impl Keymap { Keymap { bindings: vec![ b(ActionId::Play, "space", false), + // Seeking without a pointer, on the keys every player already + // seeks with (gpui names them "left"/"right"/"home"/"end", + // platform.rs:872-877). The colour card reads the same arrows + // for its sliders, but a card answers the stroke and returns + // before the keymap is consulted at all -- so these move the + // playhead only while no card is open. + b(ActionId::StepBack, "left", false), + b(ActionId::StepForward, "right", false), + b(ActionId::JumpBack, "left", true), + b(ActionId::JumpForward, "right", true), + b(ActionId::GoStart, "home", false), + b(ActionId::GoEnd, "end", false), b(ActionId::Export, "e", false), b(ActionId::Save, "s", true), b(ActionId::Copy, "c", true), @@ -711,8 +753,16 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 25); + assert_eq!(k.entries().len(), 31); assert_eq!(k.lookup("space", false), Some(ActionId::Play)); + // The seek keys: bare arrows a frame, ctrl arrows a second, and the two + // ends of the timeline. + assert_eq!(k.lookup("left", false), Some(ActionId::StepBack)); + assert_eq!(k.lookup("right", false), Some(ActionId::StepForward)); + assert_eq!(k.lookup("left", true), Some(ActionId::JumpBack)); + assert_eq!(k.lookup("right", true), Some(ActionId::JumpForward)); + assert_eq!(k.lookup("home", false), Some(ActionId::GoStart)); + assert_eq!(k.lookup("end", false), Some(ActionId::GoEnd)); assert_eq!(k.lookup("e", false), Some(ActionId::Export)); assert_eq!(k.lookup("s", true), Some(ActionId::Save)); assert_eq!(k.lookup("c", true), Some(ActionId::Copy)); @@ -927,7 +977,7 @@ mod tests { assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); // The label is the editor's column, and never the file's word for it. assert_eq!(ActionId::CancelExport.label(), "Cancel export"); - assert_eq!(ActionId::ALL.len(), 23); + assert_eq!(ActionId::ALL.len(), 29); } #[test] diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index df73209..130fda3 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -495,6 +495,14 @@ impl Player { fn act(&mut self, action: ActionId, cx: &mut Context) { match action { ActionId::Play => self.toggle_or_restart(cx), + ActionId::StepBack => self.step(-1, cx), + ActionId::StepForward => self.step(1, cx), + // A second is however many frames this timeline runs at. + ActionId::JumpBack => self.step(-(self.fps.round() as i64), cx), + ActionId::JumpForward => self.step(self.fps.round() as i64, cx), + // The ends, as a step nothing can be far enough from. + ActionId::GoStart => self.step(i64::MIN, cx), + ActionId::GoEnd => self.step(i64::MAX, cx), ActionId::Export => self.open_export(cx), ActionId::Save => self.save_project(cx), ActionId::Copy => self.copy_selected(), @@ -842,6 +850,27 @@ impl Player { cx.notify(); } + /// The keyboard's seek: whole frames along the timeline, through the same + /// door a ruler click uses -- so a step while playing keeps playing, exactly + /// as a click does. It starts from the frame the transport is showing, which + /// past the end is the last one, and that is what lets a step back off EOS + /// revive the picture ([`Player::reset_after_reseek`] clears `done`). Both + /// ends clamp, so the two go-to actions are this same step asked for more + /// frames than the timeline has. Selection is untouched: a seek is not an + /// edit, and nothing it does moves a clip index. + fn step(&mut self, frames: i64, cx: &mut Context) { + let Some(session) = &self.session else { + return; + }; + let last = ((session.timeline_duration() * self.fps).round() as i64 - 1).max(0); + let now = match self.done { + true => last, + false => i64::from(frame_at(session.now(), self.fps)), + }; + let target = now.saturating_add(frames).clamp(0, last); + self.seek(target as f64 / self.fps, cx); + } + /// Splits the clip under the playhead. Metadata only: the timeline->source /// mapping is unchanged, so nothing reseeks and no flag is touched. fn cut(&mut self, cx: &mut Context) {