From ef7689fc425edd48d9e86ef60519bd0e7be052ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 07:00:35 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20the=20export=20that=20?= =?UTF-8?q?locks=20the=20editor=20says=20so=20as=20a=20card,=20and=20takes?= =?UTF-8?q?=20two=20answers=20to=20stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An export takes the whole editor -- nothing may touch the edit list while the worker reads it -- and until now it said that in a hint line under a panel it had just switched off. The running export is drawn as what it is: the same scrim, width and raised box the export card itself uses, so the answer arrives where the question was put, with the bar, the percentage and both clocks, the row and the seats the worker really opened, the source it reads and the file it writes. The timeline is still read around it, and the ruler keeps the fill -- the one part of the progress the card does not cover. Getting out of it now takes intent, twice over. The chord is ctrl+esc: bare escape is the stroke a hand throws at anything on screen, and thrown at an export it used to delete an hour of encoding. Bare escape now does nothing at all here -- the card is not dismissable, so there is nothing left for it to mean. And the pointer's way out is a pair, never a cycle: "Cancel export" swaps the row for "Keep exporting" beside it, both on screen at once, each saying which one it is. Rebinding still works and still adds a way out rather than replacing this one, and the card shows whatever the keymap has. --- crates/app/src/export_ui.rs | 17 ++-- crates/app/src/keymap.rs | 15 ++- crates/app/src/main.rs | 6 ++ crates/app/src/player/export.rs | 9 +- crates/app/src/render.rs | 6 +- crates/app/src/tests/cards.rs | 31 +++--- crates/app/src/ui/cards.rs | 164 ++++++++++++++++++++++++++++++++ crates/app/src/ui/timeline.rs | 37 ++----- 8 files changed, 227 insertions(+), 58 deletions(-) diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index 588cdb4..1d63619 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -821,14 +821,15 @@ pub(crate) fn commit_mbps(text: &str) -> Result { } } -/// Whether a stroke gets out of a running export. Escape does, whatever -/// modifiers are held with it, for the same reason it gets out of a capture and -/// out of the overlay: it is this window's way out, and a way out that only -/// works with the right modifiers is not one. Whatever the keymap has on cancel -/// works too, so rebinding it adds a way rather than replacing the one that -/// always worked -- and that binding is still what the progress line shows. -pub(crate) fn cancels_export(key: &str, action: Option) -> bool { - key == ESCAPE || action == Some(ActionId::CancelExport) +/// Whether a stroke gets out of a running export. `ctrl+escape` does -- a chord +/// and not the bare key, which used to end an hour of encoding on the stroke a +/// hand reaches for to shut a menu it has already shut. Bare escape does nothing +/// at all here: the progress card is not dismissable, so there is nothing left +/// for it to mean. Whatever the keymap has on cancel works too, so rebinding it +/// adds a way rather than replacing this one -- and that binding is what the +/// card shows. +pub(crate) fn cancels_export(key: &str, ctrl: bool, action: Option) -> bool { + (ctrl && key == ESCAPE) || action == Some(ActionId::CancelExport) } /// A clip's share of the lane. A timeline with no length reads as one full-width diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index ba4b42e..baec5a2 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -869,7 +869,12 @@ impl Keymap { // it is a preference set once, not a stroke wanted under a hand // that is editing. b(ActionId::Theme, "h", true), - b(ActionId::CancelExport, "escape", false), + // A chord, and the only escape in this table: bare `esc` is the + // stroke a hand throws at anything on screen, and throwing it + // at a running export used to delete an hour of encoding. The + // 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 @@ -1200,7 +1205,9 @@ mod tests { assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp)); assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown)); assert_eq!(k.lookup("+", false), None); - assert_eq!(k.lookup("escape", false), Some(ActionId::CancelExport)); + // The chord, and *only* the chord: bare escape reaches no action at all. + assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport)); + assert_eq!(k.lookup("escape", false), None); // The modifier is half the chord: ctrl+e is not e. assert_eq!(k.lookup("e", true), None); assert_eq!(k.lookup("space", true), None); @@ -1222,7 +1229,7 @@ mod tests { let text = emit(&Keymap::defaults()); assert!(text.starts_with("edith-keys 1\nplay space\n")); assert!(text.contains("save ctrl+s\n")); - assert!(text.contains("cancel-export escape\n")); + assert!(text.contains("cancel-export ctrl+escape\n")); // Both directions: the file this writes is the file it reads back, and // a file read in comes out byte for byte as it went. assert_eq!(whole(&text), Keymap::defaults()); @@ -1389,7 +1396,7 @@ mod tests { assert_eq!(k.display(ActionId::Delete), "x or delete"); assert_eq!(k.display(ActionId::Undo), "z or ctrl+z"); // The one key whose common name is not gpui's. - assert_eq!(k.display(ActionId::CancelExport), "esc"); + assert_eq!(k.display(ActionId::CancelExport), "ctrl+esc"); 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"); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 0bfc639..0a0b102 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -286,6 +286,11 @@ struct Player { /// handle is held until the worker settles, because its last act is to /// delete the output file and a second export must not be what it deletes. cancelling: bool, + /// The pointer asked to cancel and the progress card is showing the pair + /// that answers it ("Keep exporting" / "Cancel export"). One press is never + /// the cancel itself: an hour of encoding must not end on a stray click, + /// which is the reason the stroke is a chord too ([`cancels_export`]). + cancel_armed: bool, /// When the running export started, and how far it had come at each sample /// since, as `(elapsed, progress)` marks. The elapsed clock and the /// rolling-window estimate the progress line reads; see [`note_progress`]. @@ -658,6 +663,7 @@ fn main() { last_target: 0, export: None, cancelling: false, + cancel_armed: false, export_started: None, export_marks: Vec::new(), // Both derived from the file when it lands, by the same diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 9666185..c310364 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -603,8 +603,12 @@ impl Player { // happens to notice it. self.export_started = Some(Instant::now()); self.export_marks.clear(); - // The card has been answered; the progress line takes the panel from - // here, and it is the running export's escape that matters now. + // A confirm left armed by the *previous* export would open this one on + // the pair, offering to cancel a job nobody has asked about yet. + self.cancel_armed = false; + // The card has been answered; the progress card takes the window from + // here ([`Player::export_progress_card`]), and it is the running + // export's chord that matters now. self.export_open = false; cx.notify(); } @@ -615,6 +619,7 @@ impl Player { if let Some(export) = &self.export { export.cancel(); self.cancelling = true; + self.cancel_armed = false; } } diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 59c8870..f54d65e 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -141,7 +141,7 @@ impl Render for Player { // would change, so cancelling is the only one that means // anything until it is over. if this.exporting().is_some() { - if cancels_export(key, action) { + if cancels_export(key, ctrl, action) { this.cancel_export(); } cx.notify(); @@ -661,6 +661,10 @@ impl Render for Player { // window. .children(self.keys_overlay(cx)) .children(self.export_card(window.viewport_size(), cx)) + // The same sheet once the card has been answered: the running + // export is the one state in this window where nothing may be + // edited, so it is drawn as what it is rather than as a strip. + .children(self.export_progress_card(cx)) // Last, so it floats over whatever opened it -- an inspector row or // a clip menu -- rather than under it. .children(self.picker_card(window.viewport_size(), cx)) diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index c162562..00bbad8 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -4,20 +4,27 @@ use super::*; #[test] -fn escape_gets_out_of_an_export_whatever_is_held_with_it() { +fn only_a_chord_gets_out_of_an_export() { use keymap::ActionId; - // The regression this guards: looking the stroke up in the keymap made - // ctrl+escape mean nothing, and an export that a modifier could trap - // the user inside of is worse than an unbound chord. - assert!(cancels_export("escape", None)); - assert!(cancels_export("escape", Some(ActionId::CancelExport))); - // A rebound cancel works as well -- it adds a way out, never replaces - // the one that always worked. - assert!(cancels_export("q", Some(ActionId::CancelExport))); + // What this guards: bare escape is the stroke a hand throws at anything on + // screen, and while an export ran it deleted the encode. The way out is the + // same key with control on it, and the card says so. + assert!(cancels_export("escape", true, Some(ActionId::CancelExport))); + assert!(!cancels_export("escape", false, None)); + // Even if something else were ever bound to bare escape, it is not this. + assert!(!cancels_export("escape", false, Some(ActionId::Play))); + // A rebound cancel works as well -- it adds a way out, never replaces the + // chord, and the keymap is what decides whether that one carries control. + assert!(cancels_export("q", false, Some(ActionId::CancelExport))); // Nothing else does, whatever it means outside an export. - assert!(!cancels_export("e", Some(ActionId::Export))); - assert!(!cancels_export("space", Some(ActionId::Play))); - assert!(!cancels_export("q", None)); + assert!(!cancels_export("e", false, Some(ActionId::Export))); + assert!(!cancels_export("space", false, Some(ActionId::Play))); + assert!(!cancels_export("q", false, None)); + // The default keymap is what the handler feeds this: the chord reaches the + // action, the bare key reaches nothing. + let k = keymap::Keymap::defaults(); + assert!(cancels_export("escape", true, k.lookup("escape", true))); + assert!(!cancels_export("escape", false, k.lookup("escape", false))); } #[test] diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 740012e..6f72c9f 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -601,6 +601,170 @@ impl Player { ) } + /// The export while it runs, on the same sheet it was asked for on: an + /// editor that takes no edit until the worker is done says so as a card and + /// not as a strip under a panel nobody may touch. Same scrim, same width, + /// same raised box as [`Player::export_card`] -- the answer arrives where + /// the question was put -- and the timeline is still read around it. + /// + /// Two things it does *not* do. It never closes: not on a press away, not + /// on `esc`. There is nothing here to dismiss while the export is still + /// running, and a modal that vanishes leaves a locked editor with no reason + /// on screen. And its cancel is two presses, never one -- an hour of + /// encoding must not end on a stray click, which is why the stroke is a + /// chord as well ([`cancels_export`]). + pub(crate) fn export_progress_card(&self, cx: &mut Context) -> Option { + let export = self.exporting()?; + let progress = export.progress().clamp(0., 1.); + let elapsed = self + .export_started + .map_or(0., |t| t.elapsed().as_secs_f32()); + // Two numbers that must both be honest: the one that counts up is + // measured, the one that counts down is a guess and says so. + let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else( + || "estimating…".to_owned(), + |s| format!("~{} left", clock(s)), + ); + // What is being read, the same files the engine names on stderr + // ("export source:"): the project's own sources, never a stand-in. + let source = match self.sources() { + [] => "the timeline".to_owned(), + [one] => file_name(&one.path), + [first, rest @ ..] => format!("{} +{} more", file_name(&first.path), rest.len()), + }; + let note = |text: SharedString| { + div() + .flex_none() + .px(px(6.)) + .text_size(px(11.)) + .text_color(rgb(FG_SECONDARY())) + .child(text) + }; + let armed = self.cancel_armed; + Some( + scrim() + .flex() + .justify_center() + .items_center() + .bg(rgba(SCRIM())) + // No `close_card` here, unlike every other sheet: a press away + // is not a way out of a running export, and the only thing that + // ends this card is the export ending. + .on_mouse_down(MouseButton::Left, swallow) + .child( + div() + .w(px(EXPORT_W)) + .on_mouse_down(MouseButton::Left, swallow) + .flex() + .flex_col() + .gap(px(6.)) + .p(px(12.)) + .rounded(px(6.)) + .bg(rgb(BG_RAISED())) + .child(div().flex_none().px(px(6.)).child("Exporting")) + // The bar itself: the same number as the percentage + // below it, and it only ever moves forward -- the + // worker's progress is a monotone `fetch_max`. + .child( + div() + .flex_none() + .mx(px(6.)) + .h(px(6.)) + .rounded(px(3.)) + .bg(rgb(BG_PANEL())) + .child( + div() + .h_full() + .w(relative(progress)) + .rounded(px(3.)) + .bg(rgb(STATUS_PROGRESS())), + ), + ) + .child(div().flex_none().px(px(6.)).text_size(px(11.)).child( + SharedString::from(format!( + "{}% · {} elapsed · {left}", + (progress * 100.) as u32, + clock(elapsed), + )), + )) + // The row that was picked, then the seats the worker + // actually opened -- so a fallback to the software + // encoder shows here rather than being invisible. + .child(note( + format!( + "{} · {}", + format_label(self.format), + export + .encoders() + .unwrap_or_else(|| "opening the encoder".to_string()), + ) + .into(), + )) + .child(note( + format!("{source} → {}", file_name(&self.export_path)).into(), + )) + .child(note( + match armed { + true => "cancelling deletes what has been written so far" + .to_string(), + false => format!( + "{} cancels · esc alone does nothing while this runs · the \ + timeline is read-only until it finishes", + self.keymap.display(ActionId::CancelExport) + ), + } + .into(), + )) + // One button, or the pair that answers it: never a + // control that cycles -- both choices are on screen at + // once, each saying which one it is. + .child( + div() + .mt(px(2.)) + .flex() + .gap(px(6.)) + .justify_end() + .when(armed, |d| { + d.child(control( + "export-keep", + 140., + ACCENT_PRIMARY(), + None, + "Keep exporting", + "leaves the export running".to_string(), + true, + cx.listener(|this, _: &ClickEvent, _, cx| { + this.cancel_armed = false; + cx.notify(); + }), + )) + }) + .child(control( + "export-cancel", + 140., + BG_RAISED(), + None, + "Cancel export", + match armed { + true => "stops the worker and deletes the part file" + .to_string(), + false => "asks first -- one press only offers the choice" + .to_string(), + }, + true, + cx.listener(move |this, _: &ClickEvent, _, cx| { + match this.cancel_armed { + true => this.cancel_export(), + false => this.cancel_armed = true, + } + cx.notify(); + }), + )), + ), + ), + ) + } + /// The custom bitrate's two pointer buttons. The typed digits were the last /// control in this card a mouse could not reach at all -- and a number that /// can only be typed is a number a hand on the pointer has to leave the diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 4e42fe9..1c60ee3 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -41,37 +41,12 @@ impl Player { rows.push(self.lane_row(lane, filled, cx)); } let (hint, filled) = if let Some(export) = self.exporting() { - let progress = export.progress(); - let elapsed = self - .export_started - .map_or(0., |t| t.elapsed().as_secs_f32()); - // Two numbers that must both be honest: the one that counts up is - // measured, the one that counts down is a guess and says so. - let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else( - || "estimating…".to_owned(), - |s| format!("~{} left", clock(s)), - ); - ( - format!( - // Clocks, then the way out, then what is encoding: at the - // 640 px floor the tail is what truncation eats, and the - // codec pair is the one part of this line the card already - // said. The escape must not be what goes missing. - "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}", - (progress * 100.) as u32, - clock(elapsed), - key(ActionId::CancelExport), - // The row that was picked; the engine's line below names the - // seats alone, since the library is what identifies a codec. - format_label(self.format), - // What the worker actually opened, so a fallback to the - // software encoder shows here rather than being invisible. - export - .encoders() - .unwrap_or_else(|| "opening the encoder".to_string()), - ), - progress, - ) + // The words are the card's now ([`Player::export_progress_card`]): + // the export is modal, so this line is under its scrim and a second + // copy of the clocks there is one that can only be read dimmed. The + // ruler keeps the number -- it is the one part of the progress the + // card does not cover, and it costs nothing. + (String::new(), export.progress()) } else { // The strokes no button carries; the rest ride on the buttons' // tooltips. Keys first: at a 640 px window the tail is what a