Merge branch 'worktree-agent-adbbf5f5c0d5f50e2'
Browse files at this commit2 changed files +83 -4
- crates/app/src/keymap.rs +54 -4
- crates/app/src/main.rs +29 -0
crates/app/src/keymap.rsmodified+54 -4
| @@ -41,6 +41,12 @@ const MAGIC: &str = "edith-keys 1"; | |||
| 41 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 41 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 42 | pub enum ActionId { | 42 | pub enum ActionId { |
| 43 | Play, | 43 | Play, |
| 44 | + StepBack, | ||
| 45 | + StepForward, | ||
| 46 | + JumpBack, | ||
| 47 | + JumpForward, | ||
| 48 | + GoStart, | ||
| 49 | + GoEnd, | ||
| 44 | Export, | 50 | Export, |
| 45 | Save, | 51 | Save, |
| 46 | Copy, | 52 | Copy, |
| @@ -68,8 +74,14 @@ pub enum ActionId { | |||
| 68 | impl ActionId { | 74 | impl ActionId { |
| 69 | /// Display order everywhere -- the editor lists them in it and | 75 | /// Display order everywhere -- the editor lists them in it and |
| 70 | /// [`Keymap::defaults`] binds them in it. | 76 | /// [`Keymap::defaults`] binds them in it. |
| 71 | - pub const ALL: [ActionId; 23] = [ | 77 | + pub const ALL: [ActionId; 29] = [ |
| 72 | ActionId::Play, | 78 | ActionId::Play, |
| 79 | + ActionId::StepBack, | ||
| 80 | + ActionId::StepForward, | ||
| 81 | + ActionId::JumpBack, | ||
| 82 | + ActionId::JumpForward, | ||
| 83 | + ActionId::GoStart, | ||
| 84 | + ActionId::GoEnd, | ||
| 73 | ActionId::Export, | 85 | ActionId::Export, |
| 74 | ActionId::Save, | 86 | ActionId::Save, |
| 75 | ActionId::Copy, | 87 | ActionId::Copy, |
| @@ -98,6 +110,12 @@ impl ActionId { | |||
| 98 | pub fn label(self) -> &'static str { | 110 | pub fn label(self) -> &'static str { |
| 99 | match self { | 111 | match self { |
| 100 | ActionId::Play => "Play / Pause", | 112 | 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", | ||
| 101 | ActionId::Export => "Export", | 119 | ActionId::Export => "Export", |
| 102 | ActionId::Save => "Save", | 120 | ActionId::Save => "Save", |
| 103 | ActionId::Copy => "Copy", | 121 | ActionId::Copy => "Copy", |
| @@ -128,6 +146,12 @@ impl ActionId { | |||
| 128 | fn name(self) -> &'static str { | 146 | fn name(self) -> &'static str { |
| 129 | match self { | 147 | match self { |
| 130 | ActionId::Play => "play", | 148 | 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", | ||
| 131 | ActionId::Export => "export", | 155 | ActionId::Export => "export", |
| 132 | ActionId::Save => "save", | 156 | ActionId::Save => "save", |
| 133 | ActionId::Copy => "copy", | 157 | ActionId::Copy => "copy", |
| @@ -162,7 +186,13 @@ impl ActionId { | |||
| 162 | /// forget. | 186 | /// forget. |
| 163 | pub fn category(self) -> Category { | 187 | pub fn category(self) -> Category { |
| 164 | match self { | 188 | 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, | ||
| 166 | ActionId::Copy | 196 | ActionId::Copy |
| 167 | | ActionId::Paste | 197 | | ActionId::Paste |
| 168 | | ActionId::Select | 198 | | ActionId::Select |
| @@ -403,6 +433,18 @@ impl Keymap { | |||
| 403 | Keymap { | 433 | Keymap { |
| 404 | bindings: vec![ | 434 | bindings: vec![ |
| 405 | b(ActionId::Play, "space", false), | 435 | 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), | ||
| 406 | b(ActionId::Export, "e", false), | 448 | b(ActionId::Export, "e", false), |
| 407 | b(ActionId::Save, "s", true), | 449 | b(ActionId::Save, "s", true), |
| 408 | b(ActionId::Copy, "c", true), | 450 | b(ActionId::Copy, "c", true), |
| @@ -711,8 +753,16 @@ mod tests { | |||
| 711 | #[test] | 753 | #[test] |
| 712 | fn every_default_stroke_reaches_its_action() { | 754 | fn every_default_stroke_reaches_its_action() { |
| 713 | let k = Keymap::defaults(); | 755 | let k = Keymap::defaults(); |
| 714 | - assert_eq!(k.entries().len(), 25); | 756 | + assert_eq!(k.entries().len(), 31); |
| 715 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); | 757 | 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)); | ||
| 716 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); | 766 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); |
| 717 | assert_eq!(k.lookup("s", true), Some(ActionId::Save)); | 767 | assert_eq!(k.lookup("s", true), Some(ActionId::Save)); |
| 718 | assert_eq!(k.lookup("c", true), Some(ActionId::Copy)); | 768 | assert_eq!(k.lookup("c", true), Some(ActionId::Copy)); |
| @@ -927,7 +977,7 @@ mod tests { | |||
| 927 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); | 977 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 928 | // The label is the editor's column, and never the file's word for it. | 978 | // The label is the editor's column, and never the file's word for it. |
| 929 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); | 979 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 930 | - assert_eq!(ActionId::ALL.len(), 23); | 980 | + assert_eq!(ActionId::ALL.len(), 29); |
| 931 | } | 981 | } |
| 932 | 982 | ||
| 933 | #[test] | 983 | #[test] |
crates/app/src/main.rsmodified+29 -0
| @@ -495,6 +495,14 @@ impl Player { | |||
| 495 | fn act(&mut self, action: ActionId, cx: &mut Context<Self>) { | 495 | fn act(&mut self, action: ActionId, cx: &mut Context<Self>) { |
| 496 | match action { | 496 | match action { |
| 497 | ActionId::Play => self.toggle_or_restart(cx), | 497 | 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), | ||
| 498 | ActionId::Export => self.open_export(cx), | 506 | ActionId::Export => self.open_export(cx), |
| 499 | ActionId::Save => self.save_project(cx), | 507 | ActionId::Save => self.save_project(cx), |
| 500 | ActionId::Copy => self.copy_selected(), | 508 | ActionId::Copy => self.copy_selected(), |
| @@ -842,6 +850,27 @@ impl Player { | |||
| 842 | cx.notify(); | 850 | cx.notify(); |
| 843 | } | 851 | } |
| 844 | 852 | ||
| 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 | + | ||
| 845 | /// Splits the clip under the playhead. Metadata only: the timeline->source | 874 | /// Splits the clip under the playhead. Metadata only: the timeline->source |
| 846 | /// mapping is unchanged, so nothing reseeks and no flag is touched. | 875 | /// mapping is unchanged, so nothing reseeks and no flag is touched. |
| 847 | fn cut(&mut self, cx: &mut Context<Self>) { | 876 | fn cut(&mut self, cx: &mut Context<Self>) { |