From b3335739850c56b5cb7f760652492e2115c6a242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 11:10:05 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ui):=20the=20room=20speaks=20a?= =?UTF-8?q?nd=20the=20loop=20closes=20at=20the=20end=20of=20the=20film?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The keys overlay showed eleven of seventy-one bindings behind a clipped plate, so sixty commands lived on no surface at all — it scrolls the whole list by category now, and it opens on ? as the contract names rather than f1. It is held, not latched: press dims the room, release restores it. Notices had nowhere to land in the darkroom, so arming loop-trim moved zero pixels and the editor could not tell an armed loop from a dead key. The ledger carries its real content — project identity, last action, export progress, position — and notices rise above it as plates with a severity spine, fed by the same queue the legacy room already writes to. Loop-trim never wrapped when the window ended on the film's last frame: the transport reached its end, halted, and the restart check found a stopped clock. Reaching the end with either loop armed now restarts, and the trim window's own start wins over the timeline's top. --- crates/app/src/keymap.rs | 15 +-- crates/app/src/main.rs | 2 +- crates/app/src/player/transport.rs | 64 ++++++++++- crates/app/src/tests/cards.rs | 2 +- crates/app/src/timeline_math.rs | 14 +++ crates/app/src/ui/stance.rs | 164 +++++++++++++++++++++++++---- 6 files changed, 229 insertions(+), 32 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 9f78e50..8637f4c 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -1143,11 +1143,12 @@ impl Keymap { // key stays the one people look for -- the modifier is what // makes it an intention ([`crate::cancels_export`]). b(ActionId::CancelExport, "escape", true), - // The help key, where every program's list of what it can do - // has always been. Free -- gpui names it "f1" - // (platform.rs:880, the keysym's own name lowercased) -- and - // not a letter, so it takes nothing away from the clip keys. - b(ActionId::ShowActions, "f1", false), + // The help key (DESIGN.md §9): held, it opens the keys + // overlay; released, it closes -- the room's own `on_key_up` + // (`ui/stance.rs`) is what makes that a hold and not a latch. + // Its own key, not `shift+/`: gpui reports a shifted symbol as + // the glyph itself, so `"?"` is what a stroke of it reports. + b(ActionId::ShowActions, "?", false), // "w" is free entirely, bare and ctrl both -- nothing else in // this table answers to it. b(ActionId::Screenshot, "w", false), @@ -1435,7 +1436,7 @@ mod tests { assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); - assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); + assert_eq!(k.lookup("?", false), Some(ActionId::ShowActions)); assert_eq!(k.lookup("h", true), Some(ActionId::Theme)); assert_eq!(k.lookup("space", false), Some(ActionId::Play)); // The seek keys: bare arrows a frame, ctrl arrows a second, and the two @@ -1705,7 +1706,7 @@ mod tests { // The label is the editor's column, and never the file's word for it. assert_eq!(ActionId::CancelExport.label(), "Cancel export"); assert_eq!(k.display(ActionId::ToggleSnap), "n"); - assert_eq!(k.display(ActionId::ShowActions), "f1"); + assert_eq!(k.display(ActionId::ShowActions), "?"); assert_eq!(k.display(ActionId::ToggleSubtitles), "t"); assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 3990867..f2eadc2 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -68,7 +68,7 @@ use engine::transform::TransformParams; use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; use gpui::{ AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, - FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, + FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, diff --git a/crates/app/src/player/transport.rs b/crates/app/src/player/transport.rs index 51d95df..c52c510 100644 --- a/crates/app/src/player/transport.rs +++ b/crates/app/src/player/transport.rs @@ -165,14 +165,24 @@ impl Player { // otherwise repaint at vsync forever. Held clear for as long as the // state does, not just on the crossing: nothing else is coming. self.seek_since = None; - if crosses_into_loop(was, Transport::Ended, self.loop_on) { + // A loop-trim window whose far edge *is* the film's last frame + // reaches Ended the same tick it would have reached the window's + // own edge, so the top-of-function restart above never gets the + // chance -- `is_playing()` there is already false by the time + // this branch runs. Folded into the same crossing the + // whole-timeline loop already used, so that race has nothing + // left to win: reaching the end while *either* loop is armed + // restarts rather than halts, regardless of which one owns it. + let armed = self.loop_on || self.loop_trim.is_some(); + if crosses_into_loop(was, Transport::Ended, armed) { // The same door the restart button and key use // ([`Player::toggle_or_restart`]), minus the `cx` that door // spends only on a repaint -- the pump is already inside one. // One seam of a one-frame seam: the restart is a fresh seek // and its reopen, not a gapless splice. + let start = loop_restart_frame(self.loop_on, self.loop_trim).unwrap_or(0); if let Some(session) = self.active_session_mut() { - session.seek(0.); + session.seek(f64::from(start) / fps); } self.reset_after_reseek(); if let Some(session) = self.active_session_mut() { @@ -451,4 +461,54 @@ mod tests { assert!(!crosses_into_loop(Transport::Ended, Transport::Ended, true)); assert!(!crosses_into_loop(Transport::Ended, Transport::Playing, true)); } + + /// `loop_restart_frame` picks the seek target the crossing above plays + /// from: the trim window's near edge when one is armed (it wins over the + /// whole-timeline loop when both happen to be set), the top of the + /// timeline for the whole-timeline loop alone, and no restart at all + /// with neither armed. + #[test] + fn loop_restart_frame_prefers_the_trim_window_then_the_whole_timeline_then_nothing() { + assert_eq!(loop_restart_frame(false, Some((30, 60))), Some(30)); + assert_eq!( + loop_restart_frame(true, Some((30, 60))), + Some(30), + "the trim window wins over the whole-timeline loop" + ); + assert_eq!(loop_restart_frame(true, None), Some(0)); + assert_eq!(loop_restart_frame(false, None), None); + } + + /// The bug this session fixed: a loop-trim window whose far edge (60) + /// *is* the film's own last frame reaches `Ended` the same tick the + /// window's own edge would have restarted it, so `is_playing()` -- + /// gating the top-of-`pump` restart -- can already be false by the time + /// that check runs. The crossing below must fire from `loop_trim` alone, + /// with `loop_on` off, and it must resume at the window's own start + /// (30), not the top of the timeline: reaching the end while a loop is + /// armed restarts, it never silently halts. + #[test] + fn a_loop_trim_window_ending_at_the_films_last_frame_restarts_on_ended() { + let loop_on = false; + let loop_trim = Some((30, 60)); + let armed = loop_on || loop_trim.is_some(); + assert!(armed, "loop_trim alone must arm the crossing"); + assert!(crosses_into_loop(Transport::Playing, Transport::Ended, armed)); + assert_eq!(loop_restart_frame(loop_on, loop_trim), Some(30)); + } + + /// A loop window sitting entirely before the film's end never reaches + /// `Ended` at all -- the top-of-`pump` restart (`should_loop_restart`, + /// gated on `is_playing()`) fires first, on the ordinary tick the + /// playhead crosses the window's far edge, exactly as + /// `should_loop_restart_only_at_the_windows_far_edge` + /// (`tests::editing`) already covers. This crossing helper only ever + /// applies to the end-of-film case above. + #[test] + fn a_mid_timeline_loop_window_never_needs_the_ended_crossing() { + use crate::timeline_math::should_loop_restart; + // Well short of the film's own end: the ordinary restart already + // fires at frame 60 without the transport ever reaching Ended. + assert!(should_loop_restart(60, Some((30, 60)))); + } } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 12ba0df..bd839e1 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -166,7 +166,7 @@ fn a_search_leaves_the_rows_it_names_under_their_own_headings() { ); // The card's own door is on the card, by name and by stroke. assert_eq!( - acts(&keys_filter("f1", &keymap)), + acts(&keys_filter("?", &keymap)), vec![ActionId::ShowActions] ); assert_eq!( diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index fe66fca..62ac230 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -362,6 +362,20 @@ pub(crate) fn should_loop_restart(frame: u32, window: Option<(u32, u32)>) -> boo window.is_some_and(|(_, hi)| frame >= hi) } +/// Where a play resumes from on crossing into [`Transport::Ended`] +/// (`Player::pump`): the loop-trim window's own near edge when one is armed, +/// *even when its far edge is the film's own last frame* -- half of all cuts +/// in a two-clip film sit on the final clip (DESIGN.md §6), so that coincidence +/// is not an edge case and must not read as "reached the end, stop". Falls +/// back to the whole-timeline loop's top, and `None` -- neither armed -- +/// restarts nothing, which is the halt this crossing otherwise means. +pub(crate) fn loop_restart_frame(loop_on: bool, loop_trim: Option<(u32, u32)>) -> Option { + match loop_trim { + Some((lo, _)) => Some(lo), + None => loop_on.then_some(0), + } +} + /// How many timeline frames a stretch of a subtitle track is worth: the one /// conversion between the two clocks a caption has -- microseconds for its /// words, frames for where it sits -- and the app-side twin of the engine's own diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index b3899ca..b89eee1 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -87,18 +87,22 @@ fn ghost_dual(player: &Player, glyph: &str, action: ActionId, stride: ActionId) ) } -/// The keys overlay (DESIGN §9, §12 step 7): every bound command as one -/// chord-and-label row, plate-styled per §4 ("readouts are plates"), shown -/// while [`Player::keys_open`] is set (the same field/guard the legacy -/// modal already used -- `Player::show_actions` sets it, `Player::close_card` -/// clears it on `esc`, both already wired through the darkroom's key -/// handler below). +/// The keys overlay (DESIGN §9, §12 step 7): every bound command, sectioned +/// by [`keymap::Category`] exactly as the legacy actions card files them +/// ([`keys_rows`]) -- reusing that registry-driven order is what makes an +/// action added anywhere land here without a second list to forget. Held +/// open by `?` -- [`crate::ui::stance::render`]'s own `on_key_down` opens it +/// on the press (bypassing the modal `overlaid()` guard, which would +/// otherwise swallow the second `?` down while the first is still up) and +/// its `on_key_up` closes it on release, so this is the room dimming one +/// fill step for as long as the key is held, never a latch (DESIGN §9: "no +/// modal cheat-sheet"). /// /// corner-cut: DESIGN §9 wants chords surfaced *in place beside their -/// controls* across every region, dimming the room one fill step; this is -/// one list plate instead, anchored over the bench/ledger footprint so it -/// never reaches the screen. Ceiling: DESIGN §12 step 7's full geographic -/// pass (each region draws its own rows when `keys_open`). +/// controls* across every region; this is one scrolling list plate instead, +/// anchored over the bench/ledger footprint so it never reaches the screen. +/// Ceiling: DESIGN §12 step 7's full geographic pass (each region draws its +/// own rows while held). fn keys_overlay(player: &Player) -> impl IntoElement { div() .id("stance-keys-overlay") @@ -111,10 +115,11 @@ fn keys_overlay(player: &Player) -> impl IntoElement { .flex() .child( div() + .id("stance-keys-list") .m_auto() - .max_h(px(BENCH_H + LEDGER_H - 16.)) - .max_w(px(420.)) - .overflow_hidden() + .h(px(BENCH_H + LEDGER_H - 16.)) + .w(px(460.)) + .overflow_y_scroll() .p(px(10.)) .rounded(px(4.)) .bg(rgb(DARK_PANEL())) @@ -123,15 +128,34 @@ fn keys_overlay(player: &Player) -> impl IntoElement { .flex() .flex_col() .gap(px(3.)) - .child(section_head("all commands · esc to close")) - .children(player.keymap.entries().iter().map(|b| { - div() + .child(section_head("all commands · hold ? · release to close")) + .children(keys_rows().into_iter().map(|row| match row { + KeyRow::Head(category) => div() + .flex_none() + .pt(px(4.)) + .text_size(px(9.)) + .text_color(rgb(INK3())) + .child(category.label().to_uppercase()) + .into_any_element(), + KeyRow::Act(action) => div() .flex() .justify_between() .gap(px(12.)) .text_size(px(9.5)) - .child(div().text_color(rgb(INK2())).child(b.action.label())) - .child(div().text_color(rgb(INK3())).child(b.chord.pretty())) + .child(div().text_color(rgb(INK2())).child(action.label())) + .child(div().text_color(rgb(INK3())).child(player.keymap.display(action))) + .into_any_element(), + KeyRow::Fixed(i) => { + let f = &keymap::FIXED[i]; + div() + .flex() + .justify_between() + .gap(px(12.)) + .text_size(px(9.5)) + .child(div().text_color(rgb(INK2())).child(f.label)) + .child(div().text_color(rgb(INK3())).child(f.chord.clone())) + .into_any_element() + } })), ) } @@ -285,9 +309,70 @@ fn bench(player: &mut Player, cx: &mut Context) -> impl IntoElement { .child(bench_stance::render(player, BENCH_H - 20., cx)) } +/// Which of the three §8 severities a notice's own words carry. Reuses +/// [`notice_tone`] (the legacy bar's own classification, by word) rather than +/// a second heuristic, and folds its four-way answer onto the darkroom's +/// three tokens: `STATUS_ERROR`/`STATUS_WARNING` are the same constants as +/// `NOTICE_DECIDE`/`NOTICE_LOOK` already (`ui/theme.rs`'s `darkroom` module +/// aliases them both ways), so the two failure/refusal tones fold straight +/// across and everything else -- success included -- reads as *told you*. +fn notice_severity(message: &str) -> u32 { + let tone = notice_tone(message); + if tone == STATUS_ERROR() { + NOTICE_DECIDE() + } else if tone == STATUS_WARNING() { + NOTICE_LOOK() + } else { + NOTICE_TELL() + } +} + +/// A notice plate (DESIGN §8): one at a time, rising above the ledger, its +/// severity a 3px left spine rather than a colour flood. Fed by the same +/// [`Player::notify_user`]/`notices` queue the legacy bar reads +/// ([`Player::notice_bar`]) -- no second notice channel. Dismissal is +/// already wired: [`render`]'s `on_key_down` calls `dismiss_notice()` on +/// every stroke, the same door the legacy handler uses. +/// +/// corner-cut: amber's "carries a jump action" is not wired -- the queue +/// only ever held plain text, no structured jump target, in either the +/// legacy bar or here. Ceiling: give `notify_user` an optional jump payload +/// once a call site actually has one to carry. +fn notice_plate(message: SharedString) -> impl IntoElement { + div() + .id("stance-notice") + .absolute() + .bottom(px(LEDGER_H + 6.)) + .left(px(12.)) + .max_w(px(360.)) + .flex() + .items_center() + .px(px(10.)) + .py(px(6.)) + .rounded(px(2.)) + .bg(rgb(DARK_PANEL())) + // The severity spine (DESIGN §8): a 3px left border, coloured, same + // shape as the legacy notice bar's own tone stripe (`notice_bar`). + .border_l(px(3.)) + .border_color(rgb(notice_severity(&message))) + .text_size(px(10.)) + .text_color(rgb(INK1())) + .child(message) +} + /// Thin strip at the bottom of the centre column: project identity, last /// action, export progress, position. Notices rise from here (DESIGN §5, §8). -fn ledger() -> impl IntoElement { +fn ledger(player: &Player, position: f64) -> impl IntoElement { + let name = match player.project_path.as_os_str().is_empty() { + true => "untitled".to_string(), + false => file_name(&player.project_path), + }; + let identity = format!("{name} · {}", if player.autosave_dirty { "unsaved" } else { "saved" }); + let last_action = player.notices.back().cloned().unwrap_or_else(|| "—".into()); + let export = player + .exporting() + .map(|h| format!("EXPORTING {:.0}%", h.progress() * 100.)); + let tc = timecode(position, player.active_fps()); div() .id("stance-ledger") .flex_none() @@ -297,9 +382,21 @@ fn ledger() -> impl IntoElement { .border_color(rgba(DARK_SEAM())) .flex() .items_center() + .gap(px(14.)) .px(px(12.)) .child(section_head("ledger")) - // hook: §12 step 7 -- project identity/state, last action, export progress, notices. + .child(div().text_size(px(9.5)).text_color(rgb(INK1())).child(identity)) + .child( + div() + .flex_1() + .min_w(px(0.)) + .truncate() + .text_size(px(9.5)) + .text_color(rgb(INK3())) + .child(last_action), + ) + .children(export.map(|e| div().text_size(px(9.5)).text_color(rgb(INK2())).child(e))) + .child(div().flex_none().text_size(px(9.5)).text_color(rgb(INK2())).child(tc)) } /// The dock: the only side panel, right, fixed width, carrying the Src/Clip @@ -342,6 +439,18 @@ pub(crate) fn render( if this.dismiss_notice() { cx.notify(); } + // DESIGN §9: "`?` held ... surfaces chords ... release restores. + // No modal cheat-sheet." Opened here, ahead of the modal guard + // below (which would otherwise swallow a second `?` down once + // `keys_open` is already true) -- `on_key_up` is the only thing + // that closes it, so there is no latch to fall through to. + if key == "?" && !ctrl { + if !this.keys_open { + this.show_actions(cx); + } + cx.notify(); + return; + } // Same modal guard the legacy handler's rebinding/keys_open/ // export_open/exporting/colour/transform/speed/EQ/silence/mix/ // subtitle-style/menu chain (`render.rs`) amounts to, read as @@ -373,6 +482,16 @@ pub(crate) fn render( this.act(action, window, cx); } })) + // The release half of the `?` hold above: whatever opened it, this is + // the one thing that closes it -- there is nothing else in the + // darkroom that sets `keys_open` true, so this cannot close a card + // `?` did not open. + .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| { + if event.keystroke.key.as_str() == "?" { + this.keys_open = false; + cx.notify(); + } + })) .size_full() .flex() .bg(rgb(DARK_CANVAS())) @@ -388,7 +507,10 @@ pub(crate) fn render( .child(screen(player, position, window, cx)) .child(time_band(player)) .child(bench(player, cx)) - .child(ledger()) + .child(ledger(player, position)) + .when_some(player.notices.front().cloned(), |el, n| { + el.child(notice_plate(n)) + }) .when(player.keys_open, |el| el.child(keys_overlay(player))), ) .child(dock(player, window_h, cx))