forge
Explore
Log in

Don't you dare go Hollow

The playhead moves from the keyboard

Browse files at this commit

05a3aee6b37a3afb7a84addfd5b69fef8ca0e3b2Ahmet Kaan GümüşParent: 951c3fc
  • feat
    • the playhead moves from the keyboard
Show full message
✨ feat(timeline): the playhead moves from the keyboard
crates/app/src/keymap.rsmodified+54 -4
@@ -41,6 +41,12 @@ const MAGIC: &str = "edith-keys 1";
4141 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
4242 pub enum ActionId {
4343 Play,
44+ StepBack,
45+ StepForward,
46+ JumpBack,
47+ JumpForward,
48+ GoStart,
49+ GoEnd,
4450 Export,
4551 Save,
4652 Copy,
@@ -68,8 +74,14 @@ pub enum ActionId {
6874 impl ActionId {
6975 /// Display order everywhere -- the editor lists them in it and
7076 /// [`Keymap::defaults`] binds them in it.
71- pub const ALL: [ActionId; 23] = [
77+ pub const ALL: [ActionId; 29] = [
7278 ActionId::Play,
79+ ActionId::StepBack,
80+ ActionId::StepForward,
81+ ActionId::JumpBack,
82+ ActionId::JumpForward,
83+ ActionId::GoStart,
84+ ActionId::GoEnd,
7385 ActionId::Export,
7486 ActionId::Save,
7587 ActionId::Copy,
@@ -98,6 +110,12 @@ impl ActionId {
98110 pub fn label(self) -> &'static str {
99111 match self {
100112 ActionId::Play => "Play / Pause",
113+ ActionId::StepBack => "One frame back",
114+ ActionId::StepForward => "One frame forward",
115+ ActionId::JumpBack => "One second back",
116+ ActionId::JumpForward => "One second forward",
117+ ActionId::GoStart => "Go to the start",
118+ ActionId::GoEnd => "Go to the last frame",
101119 ActionId::Export => "Export",
102120 ActionId::Save => "Save",
103121 ActionId::Copy => "Copy",
@@ -128,6 +146,12 @@ impl ActionId {
128146 fn name(self) -> &'static str {
129147 match self {
130148 ActionId::Play => "play",
149+ ActionId::StepBack => "step-back",
150+ ActionId::StepForward => "step-forward",
151+ ActionId::JumpBack => "jump-back",
152+ ActionId::JumpForward => "jump-forward",
153+ ActionId::GoStart => "go-start",
154+ ActionId::GoEnd => "go-end",
131155 ActionId::Export => "export",
132156 ActionId::Save => "save",
133157 ActionId::Copy => "copy",
@@ -162,7 +186,13 @@ impl ActionId {
162186 /// forget.
163187 pub fn category(self) -> Category {
164188 match self {
165- ActionId::Play => Category::Playback,
189+ ActionId::Play
190+ | ActionId::StepBack
191+ | ActionId::StepForward
192+ | ActionId::JumpBack
193+ | ActionId::JumpForward
194+ | ActionId::GoStart
195+ | ActionId::GoEnd => Category::Playback,
166196 ActionId::Copy
167197 | ActionId::Paste
168198 | ActionId::Select
@@ -403,6 +433,18 @@ impl Keymap {
403433 Keymap {
404434 bindings: vec![
405435 b(ActionId::Play, "space", false),
436+ // Seeking without a pointer, on the keys every player already
437+ // seeks with (gpui names them "left"/"right"/"home"/"end",
438+ // platform.rs:872-877). The colour card reads the same arrows
439+ // for its sliders, but a card answers the stroke and returns
440+ // before the keymap is consulted at all -- so these move the
441+ // playhead only while no card is open.
442+ b(ActionId::StepBack, "left", false),
443+ b(ActionId::StepForward, "right", false),
444+ b(ActionId::JumpBack, "left", true),
445+ b(ActionId::JumpForward, "right", true),
446+ b(ActionId::GoStart, "home", false),
447+ b(ActionId::GoEnd, "end", false),
406448 b(ActionId::Export, "e", false),
407449 b(ActionId::Save, "s", true),
408450 b(ActionId::Copy, "c", true),
@@ -711,8 +753,16 @@ mod tests {
711753 #[test]
712754 fn every_default_stroke_reaches_its_action() {
713755 let k = Keymap::defaults();
714- assert_eq!(k.entries().len(), 25);
756+ assert_eq!(k.entries().len(), 31);
715757 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
758+ // The seek keys: bare arrows a frame, ctrl arrows a second, and the two
759+ // ends of the timeline.
760+ assert_eq!(k.lookup("left", false), Some(ActionId::StepBack));
761+ assert_eq!(k.lookup("right", false), Some(ActionId::StepForward));
762+ assert_eq!(k.lookup("left", true), Some(ActionId::JumpBack));
763+ assert_eq!(k.lookup("right", true), Some(ActionId::JumpForward));
764+ assert_eq!(k.lookup("home", false), Some(ActionId::GoStart));
765+ assert_eq!(k.lookup("end", false), Some(ActionId::GoEnd));
716766 assert_eq!(k.lookup("e", false), Some(ActionId::Export));
717767 assert_eq!(k.lookup("s", true), Some(ActionId::Save));
718768 assert_eq!(k.lookup("c", true), Some(ActionId::Copy));
@@ -927,7 +977,7 @@ mod tests {
927977 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
928978 // The label is the editor's column, and never the file's word for it.
929979 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
930- assert_eq!(ActionId::ALL.len(), 23);
980+ assert_eq!(ActionId::ALL.len(), 29);
931981 }
932982
933983 #[test]
crates/app/src/main.rsmodified+29 -0
@@ -495,6 +495,14 @@ impl Player {
495495 fn act(&mut self, action: ActionId, cx: &mut Context<Self>) {
496496 match action {
497497 ActionId::Play => self.toggle_or_restart(cx),
498+ ActionId::StepBack => self.step(-1, cx),
499+ ActionId::StepForward => self.step(1, cx),
500+ // A second is however many frames this timeline runs at.
501+ ActionId::JumpBack => self.step(-(self.fps.round() as i64), cx),
502+ ActionId::JumpForward => self.step(self.fps.round() as i64, cx),
503+ // The ends, as a step nothing can be far enough from.
504+ ActionId::GoStart => self.step(i64::MIN, cx),
505+ ActionId::GoEnd => self.step(i64::MAX, cx),
498506 ActionId::Export => self.open_export(cx),
499507 ActionId::Save => self.save_project(cx),
500508 ActionId::Copy => self.copy_selected(),
@@ -842,6 +850,27 @@ impl Player {
842850 cx.notify();
843851 }
844852
853+ /// The keyboard's seek: whole frames along the timeline, through the same
854+ /// door a ruler click uses -- so a step while playing keeps playing, exactly
855+ /// as a click does. It starts from the frame the transport is showing, which
856+ /// past the end is the last one, and that is what lets a step back off EOS
857+ /// revive the picture ([`Player::reset_after_reseek`] clears `done`). Both
858+ /// ends clamp, so the two go-to actions are this same step asked for more
859+ /// frames than the timeline has. Selection is untouched: a seek is not an
860+ /// edit, and nothing it does moves a clip index.
861+ fn step(&mut self, frames: i64, cx: &mut Context<Self>) {
862+ let Some(session) = &self.session else {
863+ return;
864+ };
865+ let last = ((session.timeline_duration() * self.fps).round() as i64 - 1).max(0);
866+ let now = match self.done {
867+ true => last,
868+ false => i64::from(frame_at(session.now(), self.fps)),
869+ };
870+ let target = now.saturating_add(frames).clamp(0, last);
871+ self.seek(target as f64 / self.fps, cx);
872+ }
873+
845874 /// Splits the clip under the playhead. Metadata only: the timeline->source
846875 /// mapping is unchanged, so nothing reseeks and no flag is touched.
847876 fn cut(&mut self, cx: &mut Context<Self>) {