forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-a35afdd755531dc65'

Browse files at this commit

95cdef2cc91263c195cb7e287cc1fb9013d81682Ahmet Kaan GümüşParent: 92d90b1769daad
crates/app/src/keymap.rsmodified+1 -1
@@ -182,7 +182,7 @@ pub struct Fixed {
182 pub const FIXED: [Fixed; 3] = [182 pub const FIXED: [Fixed; 3] = [
183 Fixed {183 Fixed {
184 chord: "esc",184 chord: "esc",
185- label: "Close this card, or cancel a capture",185+ label: "Close this card or clip menu, or cancel a capture",
186 category: Category::View,186 category: Category::View,
187 },187 },
188 Fixed {188 Fixed {
crates/app/src/main.rsmodified+389 -24
@@ -15,8 +15,8 @@ use engine::{Clip, ExportHandle, Frame, PlaybackSession};
15 use gpui::{15 use gpui::{
16 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,16 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,
17 MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point,17 MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point,
18- RenderImage, SharedString, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div,18+ RenderImage, SharedString, Size, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas,
19- img, point, prelude::*, px, relative, rgb, rgba, size,19+ div, img, point, prelude::*, px, relative, rgb, rgba, size,
20 };20 };
21 21
22 /// Editor chrome: three grays and one accent, all darker than the picture so the22 /// Editor chrome: three grays and one accent, all darker than the picture so the
@@ -98,6 +98,12 @@ const KEYS_ROW_H: f32 = HIT_MIN;
98 /// keeps the card inside the smallest window no matter how many actions the98 /// keeps the card inside the smallest window no matter how many actions the
99 /// editor grows -- ten rows fit here, and the eleventh is a scroll away.99 /// editor grows -- ten rows fit here, and the eleventh is a scroll away.
100 const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H;100 const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H;
101+/// The menu a right-click on a clip opens: wide enough for the longest label
102+/// beside the stroke that does the same thing, with the click targets `HIT_MIN`
103+/// binds like every other list here.
104+const MENU_W: f32 = 260.;
105+const MENU_ROW_H: f32 = HIT_MIN;
106+const MENU_PAD: f32 = 6.;
101 107
102 /// The one key name this file still spells out, and gpui's spelling of it: it108 /// The one key name this file still spells out, and gpui's spelling of it: it
103 /// is the way out of a capture and out of the overlay, and both have to work109 /// is the way out of a capture and out of the overlay, and both have to work
@@ -188,6 +194,30 @@ enum Wave {
188 /// inserted.194 /// inserted.
189 struct AssetDrag(usize);195 struct AssetDrag(usize);
190 196
197+/// An open clip menu: which clip it was opened on, where it hangs, and whether
198+/// it has been turned over to show what that clip *is* instead of what can be
199+/// done to it. The lane and index are the ones the same click selected, so
200+/// every item acts on exactly the box under the pointer.
201+#[derive(Clone, Copy)]
202+struct ContextMenu {
203+ lane: Lane,
204+ idx: usize,
205+ at: Point<Pixels>,
206+ details: bool,
207+}
208+
209+/// What the menu offers, in the order it lists them. Every one of these is an
210+/// action a stroke already reaches -- the menu is a second way *to* the actions
211+/// and never a second version of them -- so both the label and the hint come
212+/// out of the keymap registry and the two can never disagree.
213+const MENU_ITEMS: [ActionId; 5] = [
214+ ActionId::Cut,
215+ ActionId::Delete,
216+ ActionId::Lift,
217+ ActionId::Regroup,
218+ ActionId::ToggleMute,
219+];
220+
191 struct Player {221 struct Player {
192 /// The timeline, once there is one. A run with no file opens without it and222 /// The timeline, once there is one. A run with no file opens without it and
193 /// waits: the first media import or project load is what fills it, and223 /// waits: the first media import or project load is what fills it, and
@@ -215,6 +245,10 @@ struct Player {
215 /// screen, but Lift has to know which half it was aimed at. Indices move245 /// screen, but Lift has to know which half it was aimed at. Indices move
216 /// under every edit, so this is cleared by all of them.246 /// under every edit, so this is cleared by all of them.
217 selected: Option<(Lane, usize)>,247 selected: Option<(Lane, usize)>,
248+ /// The clip menu a right-click opened, if one is up. Holds an index like
249+ /// `selected` does, so it is closed by anything that can move indices --
250+ /// every stroke, and every item of its own.
251+ context_menu: Option<ContextMenu>,
218 /// Which library row is picked, as an index into the session's sources.252 /// Which library row is picked, as an index into the session's sources.
219 /// Its own selection and not the timeline's: Delete keeps acting on the253 /// Its own selection and not the timeline's: Delete keeps acting on the
220 /// clip that was clicked in a lane, whatever the library is showing. Source254 /// clip that was clicked in a lane, whatever the library is showing. Source
@@ -366,6 +400,37 @@ impl Player {
366 self.pending_seek = true;400 self.pending_seek = true;
367 }401 }
368 402
403+ /// What an action does, wherever it was asked for -- a stroke, or the clip
404+ /// menu item that names the same action. One table, so the two can never
405+ /// come to mean different things.
406+ fn act(&mut self, action: ActionId, cx: &mut Context<Self>) {
407+ match action {
408+ ActionId::Play => self.toggle_or_restart(cx),
409+ ActionId::Export => self.open_export(cx),
410+ ActionId::Save => self.save_project(cx),
411+ ActionId::Copy => self.copy_selected(),
412+ ActionId::Paste => self.paste(cx),
413+ ActionId::Cut => self.cut(cx),
414+ ActionId::Regroup => self.regroup(cx),
415+ ActionId::Delete => self.delete_selected(cx),
416+ ActionId::Lift => self.lift_selected(cx),
417+ ActionId::Undo => self.undo(cx),
418+ ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),
419+ ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),
420+ ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),
421+ // Nothing to cancel while nothing is exporting; the export guard in
422+ // the key handler is what answers this one while there is.
423+ ActionId::CancelExport => {}
424+ }
425+ }
426+
427+ /// Whether a card owns the window. While one does the timeline under it is
428+ /// out of reach, so a right-click there opens no menu -- the same rule the
429+ /// key handler and the drop target already follow.
430+ fn modal(&self) -> bool {
431+ self.keys_open || self.export_open || self.exporting().is_some()
432+ }
433+
369 /// Jumps the timeline.434 /// Jumps the timeline.
370 fn seek(&mut self, t: f64, cx: &mut Context<Self>) {435 fn seek(&mut self, t: f64, cx: &mut Context<Self>) {
371 if self.exporting().is_some() {436 if self.exporting().is_some() {
@@ -679,6 +744,10 @@ impl Player {
679 // different file -- or none -- in another project.744 // different file -- or none -- in another project.
680 self.clipboard = None;745 self.clipboard = None;
681 self.selected = None;746 self.selected = None;
747+ // A menu can be up while a project is dropped on the window --
748+ // the scrim swallows clicks, never a drop -- and its index
749+ // would name some other timeline's clip.
750+ self.context_menu = None;
682 // A different set of sources: the row that was picked is not751 // A different set of sources: the row that was picked is not
683 // the file that index names any more.752 // the file that index names any more.
684 self.selected_asset = None;753 self.selected_asset = None;
@@ -1051,24 +1120,18 @@ impl Render for Player {
1051 cx.notify();1120 cx.notify();
1052 return;1121 return;
1053 }1122 }
1054- match action {1123+ // A clip menu names an index, and every edit below moves
1055- Some(ActionId::Play) => this.toggle_or_restart(cx),1124+ // indices -- so a stroke closes it before it acts. Escape means
1056- Some(ActionId::Export) => this.open_export(cx),1125+ // that and nothing else, which is the `esc` the keys menu
1057- Some(ActionId::Save) => this.save_project(cx),1126+ // already lists (keymap.rs `FIXED`).
1058- Some(ActionId::Copy) => this.copy_selected(),1127+ if this.context_menu.take().is_some() {
1059- Some(ActionId::Paste) => this.paste(cx),1128+ cx.notify();
1060- Some(ActionId::Cut) => this.cut(cx),1129+ if key == ESCAPE {
1061- Some(ActionId::Regroup) => this.regroup(cx),1130+ return;
1062- Some(ActionId::Delete) => this.delete_selected(cx),
1063- Some(ActionId::Lift) => this.lift_selected(cx),
1064- Some(ActionId::Undo) => this.undo(cx),
1065- Some(ActionId::ToggleMute) => {
1066- this.set_volume(|volume| volume.muted = !volume.muted, cx)
1067 }1131 }
1068- Some(ActionId::VolumeUp) => this.set_volume(|volume| volume.step(true), cx),1132+ }
1069- Some(ActionId::VolumeDown) => this.set_volume(|volume| volume.step(false), cx),1133+ if let Some(action) = action {
1070- // Nothing to cancel while nothing is exporting.1134+ this.act(action, cx);
1071- Some(ActionId::CancelExport) | None => {}
1072 }1135 }
1073 }))1136 }))
1074 // The whole window is the drop target: gpui turns an external file1137 // The whole window is the drop target: gpui turns an external file
@@ -1178,6 +1241,9 @@ impl Render for Player {
1178 // the picture nothing the rest of the time.1241 // the picture nothing the rest of the time.
1179 .children(self.notice_bar(cx))1242 .children(self.notice_bar(cx))
1180 .child(self.panel(position, duration, playing, cx))1243 .child(self.panel(position, duration, playing, cx))
1244+ // Over the panel it was opened on, and under the cards: it is only
1245+ // ever up while neither of them is (`modal`).
1246+ .children(self.context_card(window.viewport_size(), cx))
1181 // Last, so they are over everything -- they take no room in the1247 // Last, so they are over everything -- they take no room in the
1182 // column, and only one of the two is ever up.1248 // column, and only one of the two is ever up.
1183 .children(self.keys_overlay(cx))1249 .children(self.keys_overlay(cx))
@@ -1906,6 +1972,188 @@ impl Player {
1906 )1972 )
1907 }1973 }
1908 1974
1975+ /// The menu a right-click on a clip opens: what that clip can be given,
1976+ /// each item beside the stroke that does the very same thing, and a
1977+ /// turn-over side that says what the clip *is*. An item that would do
1978+ /// nothing where the playhead is standing is dimmed and takes no click
1979+ /// rather than disappearing, so the menu reads the same every time.
1980+ ///
1981+ /// Every item goes through [`Player::act`], the table the key handler uses:
1982+ /// an item is its stroke, asked for with the mouse. Plain divs like the
1983+ /// rest of this window, so the root keeps the keyboard and escape still
1984+ /// reaches the handler that closes this.
1985+ fn context_card(
1986+ &self,
1987+ viewport: Size<Pixels>,
1988+ cx: &mut Context<Self>,
1989+ ) -> Option<impl IntoElement> {
1990+ let menu = self.context_menu?;
1991+ let session = self.session.as_ref()?;
1992+ let clip = *session.lane_clips(menu.lane).get(menu.idx)?;
1993+ let playhead = frame_at(session.now(), self.fps);
1994+ let path = session.sources().get(clip.source).cloned()?;
1995+ let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps);
1996+ let row = |n: usize| {
1997+ div()
1998+ .id(("menu", n))
1999+ .flex()
2000+ // The floor, not the height: a long label wrapping must not
2001+ // paint over the item under it.
2002+ .min_h(px(MENU_ROW_H))
2003+ .items_center()
2004+ .justify_between()
2005+ .gap(px(12.))
2006+ .px(px(6.))
2007+ .rounded(px(3.))
2008+ };
2009+ let mut rows: Vec<AnyElement> = Vec::new();
2010+ if menu.details {
2011+ // Read-only, so no ids and no hover: this side is a card, not a
2012+ // list of things to click. Each value is one truncated line, which
2013+ // is what keeps the height below the one the clamp was given.
2014+ for (label, value) in [
2015+ ("File", file_name(&path)),
2016+ ("Path", path.display().to_string()),
2017+ (
2018+ "Source range",
2019+ format!("{} – {}", secs(clip.in_frame), secs(clip.out_frame)),
2020+ ),
2021+ ("This clip", secs(clip.len())),
2022+ (
2023+ "Source duration",
2024+ secs(source_frames(lane_clips(session), clip.source)),
2025+ ),
2026+ ] {
2027+ rows.push(
2028+ row(rows.len())
2029+ .child(label)
2030+ .child(
2031+ div()
2032+ .min_w(px(0.))
2033+ .truncate()
2034+ // A size smaller than the labels: a timecode
2035+ // pair is 25 characters and has to fit beside
2036+ // its label inside `MENU_W`.
2037+ .text_size(px(11.))
2038+ .text_color(rgb(INK_DIM))
2039+ .child(value),
2040+ )
2041+ .into_any_element(),
2042+ );
2043+ }
2044+ } else {
2045+ for action in MENU_ITEMS {
2046+ let enabled = applicable(&clip, action, playhead);
2047+ // The one item that is not about this clip says so, and says it
2048+ // here rather than in the registry: the stroke is global too,
2049+ // but its row in the keys menu is not sitting on a clip.
2050+ let label = if action == ActionId::ToggleMute {
2051+ format!("{} (global)", action.label())
2052+ } else {
2053+ action.label().to_string()
2054+ };
2055+ rows.push(
2056+ row(rows.len())
2057+ .child(label)
2058+ .child(
2059+ div()
2060+ .text_color(rgb(INK_DIM))
2061+ .child(self.keymap.display(action)),
2062+ )
2063+ .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())
2064+ .when(enabled, |d| {
2065+ d.cursor_pointer()
2066+ .hover(|s| s.bg(rgb(HOVER)))
2067+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
2068+ // Closed first: the action moves the very
2069+ // indices this menu is holding.
2070+ this.context_menu = None;
2071+ this.act(action, cx);
2072+ }))
2073+ })
2074+ .into_any_element(),
2075+ );
2076+ }
2077+ rows.push(
2078+ row(rows.len())
2079+ .cursor_pointer()
2080+ .hover(|s| s.bg(rgb(HOVER)))
2081+ .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
2082+ if let Some(menu) = &mut this.context_menu {
2083+ menu.details = true;
2084+ }
2085+ cx.notify();
2086+ }))
2087+ .child("Properties")
2088+ // No stroke reaches this one, and a blank column would read
2089+ // as one that was forgotten.
2090+ .child(div().text_color(rgb(INK_DIM)).child("…"))
2091+ .into_any_element(),
2092+ );
2093+ }
2094+ let (x, y) = menu_at(
2095+ menu.at,
2096+ viewport,
2097+ MENU_PAD * 2. + rows.len() as f32 * MENU_ROW_H,
2098+ );
2099+ let full: SharedString = path.display().to_string().into();
2100+ Some(
2101+ div()
2102+ .absolute()
2103+ .inset_0()
2104+ // Click away closes it, either button, and the press is
2105+ // swallowed so nothing under the menu also takes it. No tint,
2106+ // unlike the modal cards: the timeline this menu is about has
2107+ // to stay readable behind it.
2108+ .on_mouse_down(
2109+ MouseButton::Left,
2110+ cx.listener(|this, _: &MouseDownEvent, _, cx| {
2111+ this.context_menu = None;
2112+ cx.notify();
2113+ cx.stop_propagation();
2114+ }),
2115+ )
2116+ .on_mouse_down(
2117+ MouseButton::Right,
2118+ cx.listener(|this, _: &MouseDownEvent, _, cx| {
2119+ this.context_menu = None;
2120+ cx.notify();
2121+ cx.stop_propagation();
2122+ }),
2123+ )
2124+ .child(
2125+ div()
2126+ // Only so the details side can carry a tooltip, which
2127+ // gpui gives to identified elements alone.
2128+ .id("menu-card")
2129+ .absolute()
2130+ .left(px(x))
2131+ .top(px(y))
2132+ .w(px(MENU_W))
2133+ .flex()
2134+ .flex_col()
2135+ .p(px(MENU_PAD))
2136+ .rounded(px(6.))
2137+ .bg(rgb(SURFACE))
2138+ // Painted after the scrim, so this listener runs first
2139+ // (gpui bubbles mouse events in reverse, window.rs:3705)
2140+ // and a press meant for an item never closes the menu
2141+ // out from under its own click.
2142+ .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| {
2143+ cx.stop_propagation()
2144+ })
2145+ .on_mouse_down(MouseButton::Right, |_: &MouseDownEvent, _, cx| {
2146+ cx.stop_propagation()
2147+ })
2148+ // The one value the details side has to truncate.
2149+ .when(menu.details, |d| {
2150+ d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into())
2151+ })
2152+ .children(rows),
2153+ ),
2154+ )
2155+ }
2156+
1909 /// One lane of the edit list made visible: a fixed header saying which lane2157 /// One lane of the edit list made visible: a fixed header saying which lane
1910 /// it is, then a bed with a box per clip, placed and sized by its share of2158 /// it is, then a bed with a box per clip, placed and sized by its share of
1911 /// the timeline. A cut adds a box without moving anything, a delete closes2159 /// the timeline. A cut adds a box without moving anything, a delete closes
@@ -2041,6 +2289,26 @@ impl Player {
2041 cx.notify();2289 cx.notify();
2042 }),2290 }),
2043 )2291 )
2292+ // The right button selects exactly as the left one
2293+ // does -- the menu acts on the clip it names, so
2294+ // opening one has to pick it -- and then hangs the
2295+ // menu at the pointer.
2296+ .on_mouse_down(
2297+ MouseButton::Right,
2298+ cx.listener(move |this, event: &MouseDownEvent, _, cx| {
2299+ if this.modal() {
2300+ return;
2301+ }
2302+ this.selected = Some((lane, i));
2303+ this.context_menu = Some(ContextMenu {
2304+ lane,
2305+ idx: i,
2306+ at: event.position,
2307+ details: false,
2308+ });
2309+ cx.notify();
2310+ }),
2311+ )
2044 // Under the label row, never through it.2312 // Under the label row, never through it.
2045 .children(wave.filter(|_| audio).and_then(|wave| {2313 .children(wave.filter(|_| audio).and_then(|wave| {
2046 let inner: AnyElement = match wave {2314 let inner: AnyElement = match wave {
@@ -2233,6 +2501,43 @@ fn source_frames<'a>(clips: impl Iterator<Item = &'a Clip>, source: usize) -> u3
2233 .unwrap_or(0)2501 .unwrap_or(0)
2234 }2502 }
2235 2503
2504+/// Which timeline frame the playhead is on, by the rule the engine's own edits
2505+/// use (playback.rs `secs_to_frame`): the frame that has started, with the
2506+/// epsilon that keeps a clock sitting exactly on a boundary from reading as the
2507+/// frame before it. Only ever a hint here -- what an edit does is still the
2508+/// engine's answer, taken from the same seconds.
2509+fn frame_at(secs: f64, fps: f64) -> u32 {
2510+ (secs * fps + 1e-6).floor().max(0.) as u32
2511+}
2512+
2513+/// Whether the clip menu offers `action` on the clip it was opened on. Two of
2514+/// the items act on the *playhead* rather than on the clip, so a menu opened
2515+/// away from it dims them instead of looking broken when they are clicked.
2516+fn applicable(clip: &Clip, action: ActionId, playhead: u32) -> bool {
2517+ match action {
2518+ // Splits this clip only from inside it: at either edge there is nothing
2519+ // to split off (project.rs `splittable`).
2520+ ActionId::Cut => clip.start < playhead && playhead < clip.end(),
2521+ // Rejoins whatever meets at the playhead, so it can mean something only
2522+ // at an edge of this clip. Whether those two halves were ever one take
2523+ // is the engine's question, and it words that refusal itself.
2524+ ActionId::Regroup => playhead == clip.start || playhead == clip.end(),
2525+ _ => true,
2526+ }
2527+}
2528+
2529+/// Where the menu actually hangs: at the pointer, pulled back inside the window
2530+/// when it would not fit -- an item off the bottom edge is an item nobody can
2531+/// click. Never negative, so a window smaller than the menu loses the bottom of
2532+/// it rather than the top, where the items are.
2533+fn menu_at(at: Point<Pixels>, viewport: Size<Pixels>, height: f32) -> (f32, f32) {
2534+ let fit = |v: f32, size: f32, room: f32| v.min(room - size).max(0.);
2535+ (
2536+ fit(f32::from(at.x), MENU_W, f32::from(viewport.width)),
2537+ fit(f32::from(at.y), height, f32::from(viewport.height)),
2538+ )
2539+}
2540+
2236 /// Whether the Add button does anything: a row picked, a timeline to put it on,2541 /// Whether the Add button does anything: a row picked, a timeline to put it on,
2237 /// and no export reading that timeline. A button that would do nothing is dimmed2542 /// and no export reading that timeline. A button that would do nothing is dimmed
2238 /// and takes no click, like every other one here.2543 /// and takes no click, like every other one here.
@@ -2674,11 +2979,12 @@ mod tests {
2674 use super::{2979 use super::{
2675 ACCENT, CONTROL_H, Clip, HEADER_GAP, HEADER_W, HIT_MIN, INK, INK_DIM, KEYS_ROW_H,2980 ACCENT, CONTROL_H, Clip, HEADER_GAP, HEADER_W, HIT_MIN, INK, INK_DIM, KEYS_ROW_H,
2676 KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W,2981 KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W,
2677- Lane, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE,2982+ Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED,
2678- SWATCH_W, Volume, WAVE_BPS, WAVE_COL, Wave, can_add, cancels_export, envelope, export_path,2983+ SOURCE_TINTS, SURFACE, SWATCH_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, can_add,
2679- export_settings, frac_along, is_bare_modifier, is_project, keymap, lane_clips, marked,2984+ cancels_export, envelope, export_path, export_settings, frac_along, frame_at,
2680- normalise, project_path, push_digit, scrub_due, show_label, source_frames, source_tint,2985+ is_bare_modifier, is_project, keymap, lane_clips, marked, menu_at, normalise, project_path,
2681- start_frac, timecode, unseen_sources, width_frac, window_title,2986+ push_digit, scrub_due, show_label, source_frames, source_tint, start_frac, timecode,
2987+ unseen_sources, width_frac, window_title,
2682 };2988 };
2683 use engine::PlaybackSession;2989 use engine::PlaybackSession;
2684 use gpui::{Bounds, Pixels, point, px, size};2990 use gpui::{Bounds, Pixels, point, px, size};
@@ -2732,6 +3038,64 @@ mod tests {
2732 assert_eq!(source_frames([].iter(), 0), 0);3038 assert_eq!(source_frames([].iter(), 0), 0);
2733 }3039 }
2734 3040
3041+ /// What the clip menu offers, and where it hangs. The two items that act on
3042+ /// the playhead rather than on the clicked clip are the ones that can be
3043+ /// inapplicable, and a menu at the edge of the window has to come back
3044+ /// inside it or its last item cannot be clicked at all.
3045+ #[test]
3046+ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
3047+ use keymap::{ActionId, Keymap};
3048+ // Frames 30..90 of the timeline, taken from the head of its source.
3049+ let clip = Clip {
3050+ start: 30,
3051+ in_frame: 0,
3052+ out_frame: 60,
3053+ source: 0,
3054+ link: None,
3055+ };
3056+ assert_eq!(clip.end(), 90);
3057+ // Cut splits from inside only: neither edge has anything to split off.
3058+ assert!(applicable(&clip, ActionId::Cut, 31));
3059+ assert!(applicable(&clip, ActionId::Cut, 89));
3060+ assert!(!applicable(&clip, ActionId::Cut, 30));
3061+ assert!(!applicable(&clip, ActionId::Cut, 90));
3062+ assert!(!applicable(&clip, ActionId::Cut, 200));
3063+ // Regroup is the other way round: only where this clip meets another.
3064+ assert!(applicable(&clip, ActionId::Regroup, 30));
3065+ assert!(applicable(&clip, ActionId::Regroup, 90));
3066+ assert!(!applicable(&clip, ActionId::Regroup, 60));
3067+ // The rest act on the clip that was clicked, so they always mean
3068+ // something -- the engine words its own refusals.
3069+ for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] {
3070+ assert!(applicable(&clip, action, 0));
3071+ assert!(applicable(&clip, action, 60));
3072+ }
3073+ // The playhead frame is the engine's own rule, boundary included.
3074+ assert_eq!(frame_at(1.0, 30.), 30);
3075+ assert_eq!(frame_at(0.0, 30.), 0);
3076+ assert_eq!(frame_at(-1.0, 30.), 0);
3077+ // Where it hangs: at the pointer when it fits, back inside when not.
3078+ let viewport = size(px(800.), px(400.));
3079+ assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.));
3080+ assert_eq!(
3081+ menu_at(point(px(700.), px(380.)), viewport, 150.),
3082+ (800. - MENU_W, 250.)
3083+ );
3084+ // A window smaller than the menu loses its bottom, never its top.
3085+ assert_eq!(
3086+ menu_at(point(px(90.), px(40.)), size(px(100.), px(50.)), 150.),
3087+ (0., 0.)
3088+ );
3089+ // Every item is an action the registry knows, so the menu and the keys
3090+ // menu say the same thing about it -- and none of them is unreachable
3091+ // by keyboard, which is what makes the hint column worth drawing.
3092+ let keymap = Keymap::defaults();
3093+ for action in MENU_ITEMS {
3094+ assert!(ActionId::ALL.contains(&action), "{action:?} is not listed");
3095+ assert_ne!(keymap.display(action), "unbound", "{action:?}");
3096+ }
3097+ }
3098+
2735 /// The refusal path, end to end against the real files: an incompatible3099 /// The refusal path, end to end against the real files: an incompatible
2736 /// import changes nothing, and the library mirrors `sources()` 1:1, so a3100 /// import changes nothing, and the library mirrors `sources()` 1:1, so a
2737 /// refused file cannot leave a row behind.3101 /// refused file cannot leave a row behind.
@@ -3497,6 +3861,7 @@ fn main() {
3497 done: false,3861 done: false,
3498 ruler: Rc::default(),3862 ruler: Rc::default(),
3499 selected: None,3863 selected: None,
3864+ context_menu: None,
3500 selected_asset: None,3865 selected_asset: None,
3501 waves: HashMap::new(),3866 waves: HashMap::new(),
3502 clipboard: None,3867 clipboard: None,