diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index a7577d4..cdf19b9 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -50,12 +50,21 @@ impl Player { // not that. let cut = session.cut_at(f64::from(at) / self.fps); if cut { + // Only a split that happened drops the selection: a refusal is + // "NOTHING TO SPLIT", and the clip in hand is still the clip the + // next Delete, `x` or menu acts on -- clearing it there left the + // user with nothing picked and told them nothing about it. A + // real split is the other way round: the cut it leaves makes the + // picked index name a different clip, so the mark has to go. + // [`Player::regroup`] below has always cleared inside its own + // success branch; this is the same rule on the other half of the + // pair. + self.selected.clear(); self.notify_user("SPLIT".into()); } else { self.notify_user("NOTHING TO SPLIT — the playhead is already on a cut".into()); } } - self.selected.clear(); cx.notify(); } @@ -72,10 +81,7 @@ impl Player { if session.regroup_at(session.now()) { self.selected.clear(); } else { - self.notify_user( - "NOTHING TO REGROUP — no cut under the playhead" - .into(), - ); + self.notify_user("NOTHING TO REGROUP — no cut under the playhead".into()); } } cx.notify(); @@ -97,9 +103,7 @@ impl Player { ); } } - (Some(_), None) => { - self.notify_user("NOTHING DETACHED — nothing selected".into()) - } + (Some(_), None) => self.notify_user("NOTHING DETACHED — nothing selected".into()), (None, _) => {} } cx.notify(); @@ -126,9 +130,7 @@ impl Player { // index (a stroke nobody saw) is not a thing to group. let picks = self.marks().0; match (&mut self.session, self.selected.anchor(), picks.len()) { - (_, None, _) => { - self.notify_user("NOTHING GROUPED — nothing selected".into()) - } + (_, None, _) => self.notify_user("NOTHING GROUPED — nothing selected".into()), // The hand's group: every pick, one id. (Some(session), _, 2..) => { if let Err(e) = session.group_all(&picks) { @@ -146,10 +148,9 @@ impl Player { self.notify_user(format!("NOT GROUPED — {e}").into()); } } - None => self.notify_user( - "NOTHING TO GROUP WITH — no clip covers these frames" - .into(), - ), + None => { + self.notify_user("NOTHING TO GROUP WITH — no clip covers these frames".into()) + } }, (None, ..) => {} } @@ -237,9 +238,7 @@ impl Player { self.notify_user("NOTHING LIFTED — that half is no longer there".into()); } } - (Some(_), None) => { - self.notify_user("NOTHING LIFTED — nothing selected".into()) - } + (Some(_), None) => self.notify_user("NOTHING LIFTED — nothing selected".into()), (None, _) => {} } cx.notify(); @@ -409,11 +408,7 @@ impl Player { // Everything else that could refuse (a clip that is not there) // cannot be dragged. false if from.kind != to.kind => self.notify_user( - format!( - "NOT ON {} — a {kind} clip takes a {lanes} lane", - to.label() - ) - .into(), + format!("NOT ON {} — a {kind} clip takes a {lanes} lane", to.label()).into(), ), // Picked up and put back down where it was: a click, and a click // says nothing. @@ -535,10 +530,7 @@ impl Player { }, // The row is greyed and says why in the list; here it says why at // the moment somebody tried to use it anyway. - (None, Some(_)) => Some( - "NOT PLACED — that subtitle track has no cues" - .to_string(), - ), + (None, Some(_)) => Some("NOT PLACED — that subtitle track has no cues".to_string()), (_, None) => Some("NOT PLACED — no file open".to_string()), }; match (text, marked) { @@ -1293,12 +1285,7 @@ impl Player { /// a project can gain, and the one remove that applies to this lane's kind /// ([`oracle::lane_items`]). Nothing is selected -- a head owns no clip -- /// which is [`Player::open_gap_menu`]'s rule on the other empty target. - pub(crate) fn open_head_menu( - &mut self, - lane: Lane, - at: Point, - cx: &mut Context, - ) { + pub(crate) fn open_head_menu(&mut self, lane: Lane, at: Point, cx: &mut Context) { if self.modal() || self.session.is_none() { return; } @@ -1698,19 +1685,14 @@ impl Player { [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), _ => self.selected.anchor(), }) else { - self.notify_user( - "NOTHING TO CROSSFADE — no audio clip selected".into(), - ); + self.notify_user("NOTHING TO CROSSFADE — no audio clip selected".into()); cx.notify(); return; }; let frames = self.fps.round().max(1.) as u32; if let Some(session) = &mut self.session { if !session.crossfade(lane, idx, frames) { - self.notify_user( - "NOTHING TO CROSSFADE — no neighbour end to end" - .into(), - ); + self.notify_user("NOTHING TO CROSSFADE — no neighbour end to end".into()); } } cx.notify(); @@ -1730,9 +1712,7 @@ impl Player { [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), _ => self.selected.anchor(), }) else { - self.notify_user( - "NOTHING TO DISSOLVE — no video clip selected".into(), - ); + self.notify_user("NOTHING TO DISSOLVE — no video clip selected".into()); cx.notify(); return; }; @@ -1747,10 +1727,7 @@ impl Player { self.fps.round().max(1.) as u32 }; if !session.set_transition_out(lane, idx, frames) { - self.notify_user( - "NOTHING TO DISSOLVE — no neighbour end to end" - .into(), - ); + self.notify_user("NOTHING TO DISSOLVE — no neighbour end to end".into()); } else if removing { self.notify_user("DISSOLVE REMOVED — the clips cut again".into()); } diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 04ed625..d38aa98 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -109,11 +109,9 @@ fn a_song_opens_the_window_by_itself() { // ...and it places, on the audio lane, through the door `insert_source` // uses: a second copy of the song at the playhead. session.seek(1.0); - assert!( - session - .place_stream_at(1.0, &path, 0, Some(Lane::A1)) - .expect("its own file is on this timeline") - ); + assert!(session + .place_stream_at(1.0, &path, 0, Some(Lane::A1)) + .expect("its own file is on this timeline")); assert_eq!(session.lane_clips(Lane::A1).len(), 2); assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture"); @@ -345,13 +343,11 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { ); // ...and the same reading with a clip under it is the clip menu, untouched: // the flag is off wherever a `Clip` was clicked. - assert!( - menu_items(Ctx { - timeline: true, - ..Ctx::default() - }) - .contains(&ActionId::Cut) - ); + assert!(menu_items(Ctx { + timeline: true, + ..Ctx::default() + }) + .contains(&ActionId::Cut)); } /// A timeline with a subtitle palette and an empty subtitle lane: what a @@ -617,6 +613,20 @@ fn the_playhead_actions_still_work_with_a_caption_marked() { let clips = session.lane_clips(Lane::V1).len(); assert!(session.cut_at(2.0), "the playhead splits the clip under it"); assert_eq!(session.lane_clips(Lane::V1).len(), clips + 1); + // The refusal is a real state and not a defence against nothing: the + // playhead is standing on the seam the split just left, which is exactly the + // stroke `Player::cut` words as "NOTHING TO SPLIT — the playhead is already + // on a cut". + assert!( + !session.cut_at(2.0), + "a second split on the seam is refused, which is the state the door's \ + selection gate is about" + ); + assert_eq!( + session.lane_clips(Lane::V1).len(), + clips + 1, + "and adds none" + ); assert!(session.regroup_at(2.0), "and the seam rejoins"); assert_eq!(session.lane_clips(Lane::V1).len(), clips); assert_eq!(session.sub_lane(lane).len(), 1, "the caption is untouched"); @@ -939,16 +949,14 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { } assert!(!whole(ActionId::Delete, live).yes()); assert!(!whole(ActionId::Paste, live).yes()); - assert!( - whole( - ActionId::Paste, - Ctx { - clipboard: true, - ..live - } - ) - .yes() - ); + assert!(whole( + ActionId::Paste, + Ctx { + clipboard: true, + ..live + } + ) + .yes()); assert!(!whole(ActionId::CancelExport, live).yes()); let busy = Ctx { exporting: true, @@ -988,7 +996,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.)); assert_eq!( menu_at(point(px(700.), px(380.)), viewport, 150.), - (800. - crate::layout::MENU_EDGE - MENU_W, 400. - crate::layout::MENU_EDGE - 150.) + ( + 800. - crate::layout::MENU_EDGE - MENU_W, + 400. - crate::layout::MENU_EDGE - 150. + ) ); // A window smaller than the menu loses its bottom, never its top: the // top-left margin wins over the bottom-right one, because the items are @@ -1165,16 +1176,14 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { assert!(row_enable(RowItem::RemoveWithClips, placed).yes()); let unplaced = row_items(live); assert!(unplaced.contains(&RowItem::Remove) && !unplaced.contains(&RowItem::RemoveWithClips)); - assert!( - !row_enable( - RowItem::RemoveWithClips, - RowCtx { - exporting: true, - ..placed - } - ) - .yes() - ); + assert!(!row_enable( + RowItem::RemoveWithClips, + RowCtx { + exporting: true, + ..placed + } + ) + .yes()); assert!(!row_enable(RowItem::Add, RowCtx::default()).yes()); // Every refusal is short enough to sit in the hint column beside its // label, the clip menu's rule. @@ -1282,7 +1291,11 @@ fn the_hanging_menus_mount_at_the_room_root_and_their_rows_wear_chords_not_prose } // §9: no junk drawer. A label that fits the plate whole beside its // chord, and never a sentence. - assert!(item.label().split_whitespace().count() <= 4, "{}", item.label()); + assert!( + item.label().split_whitespace().count() <= 4, + "{}", + item.label() + ); } // The two removes must not read as the same verb now that the column // beside them is empty. @@ -1604,11 +1617,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() { let frames = session.file_frames(&second); // Through the engine door `insert_source` uses, with the row's own // stream: the button, the drop and this are one call. - assert!( - session - .place_stream_at(2.0, &second, 0, None) - .expect("av2 is already on the timeline") - ); + assert!(session + .place_stream_at(2.0, &second, 0, None) + .expect("av2 is already on the timeline")); // The whole of source 1 went in and nothing was painted over: the // timeline is longer by exactly that file. assert_eq!(session.timeline_duration(), 9.0); @@ -1635,11 +1646,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() { let path = session.sources()[0].path.clone(); let frames = session.file_frames(&path); let end = session.timeline_duration(); - assert!( - session - .place_stream_at(end, &path, 1, None) - .expect("the French track shares the timeline's parameters") - ); + assert!(session + .place_stream_at(end, &path, 1, None) + .expect("the French track shares the timeline's parameters")); assert_eq!(session.sources()[1].audio_stream, 1); assert_eq!(session.timeline_duration(), end * 2.0); // Both rows are the same file, so both rows are that file's length -- @@ -1689,11 +1698,9 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { // ...and what the release does with it: the frame back through the same // rate every box is drawn at, into the door the Add button uses too. - assert!( - session - .place_stream_at(f64::from(at) / fps, &second, 0, None) - .expect("av2 is already on this timeline") - ); + assert!(session + .place_stream_at(f64::from(at) / fps, &second, 0, None) + .expect("av2 is already on this timeline")); let head = |lane| { session .lane_clips(lane) @@ -1727,11 +1734,9 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() { session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); let end = session.timeline_duration(); - assert!( - session - .place_stream_at(end, &second, 0, None) - .expect("a file just imported is on this timeline") - ); + assert!(session + .place_stream_at(end, &second, 0, None) + .expect("a file just imported is on this timeline")); let streams = HashMap::new(); let rows = |session: &PlaybackSession| { library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len() @@ -2058,11 +2063,9 @@ fn a_track_can_be_added_dropped_on_edited_and_taken_back() { // A library row let go over that row: the same door the Add button // uses, told which lane it was let go over. let path = session.sources()[0].path.clone(); - assert!( - session - .place_stream_at(1.0, &path, 0, Some(v2)) - .expect("its own file is on this timeline") - ); + assert!(session + .place_stream_at(1.0, &path, 0, Some(v2)) + .expect("its own file is on this timeline")); assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead"); // ...with the sound it came with, on the row of its own the drop added: @@ -2149,22 +2152,18 @@ fn a_selection_drag_moves_every_pick_by_the_same_delta() { // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in, // appended to the open bed and rippling nothing. - assert!( - session - .place_stream_at(10.0, &second, 0, None) - .expect("av2 is on this timeline") - ); + assert!(session + .place_stream_at(10.0, &second, 0, None) + .expect("av2 is on this timeline")); let clip0 = session.lane_clips(Lane::V1)[0]; let clip1 = session.lane_clips(Lane::V1)[1]; assert_eq!((clip0.start, clip1.start), (0, 300)); // clipC on a second video row, well past both of the above. let v2 = session.add_lane(LaneKind::Video); - assert!( - session - .place_stream_at(20.0, &path, 0, Some(v2)) - .expect("test_av.mp4 is on this timeline") - ); + assert!(session + .place_stream_at(20.0, &path, 0, Some(v2)) + .expect("test_av.mp4 is on this timeline")); let clip_c = session.lane_clips(v2)[0]; assert_eq!(clip_c.start, 600); @@ -2217,28 +2216,22 @@ fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() { session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); - assert!( - session - .place_stream_at(10.0, &second, 0, None) - .expect("av2 is on this timeline") - ); + assert!(session + .place_stream_at(10.0, &second, 0, None) + .expect("av2 is on this timeline")); let clip0 = session.lane_clips(Lane::V1)[0]; let clip1 = session.lane_clips(Lane::V1)[1]; let v2 = session.add_lane(LaneKind::Video); - assert!( - session - .place_stream_at(0.0, &path, 0, Some(v2)) - .expect("test_av.mp4 is on this timeline") - ); + assert!(session + .place_stream_at(0.0, &path, 0, Some(v2)) + .expect("test_av.mp4 is on this timeline")); let clip_c = session.lane_clips(v2)[0]; // A clip clip1 is not picked, blocking the road on V2 the drag is about // to try: clip1 dragged onto V2 lands its head inside this one. - assert!( - session - .place_stream_at(10.0, &second, 0, Some(v2)) - .expect("av2 is on this timeline") - ); + assert!(session + .place_stream_at(10.0, &second, 0, Some(v2)) + .expect("av2 is on this timeline")); let blocker = session.lane_clips(v2)[1]; assert_eq!(blocker.start, 300); @@ -2293,20 +2286,16 @@ fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() { session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); - assert!( - session - .place_stream_at(10.0, &second, 0, None) - .expect("av2 is on this timeline") - ); + assert!(session + .place_stream_at(10.0, &second, 0, None) + .expect("av2 is on this timeline")); let clip0 = session.lane_clips(Lane::V1)[0]; let clip1 = session.lane_clips(Lane::V1)[1]; let v2 = session.add_lane(LaneKind::Video); - assert!( - session - .place_stream_at(20.0, &path, 0, Some(v2)) - .expect("test_av.mp4 is on this timeline") - ); + assert!(session + .place_stream_at(20.0, &path, 0, Some(v2)) + .expect("test_av.mp4 is on this timeline")); let clip_c = session.lane_clips(v2)[0]; // Copied in click order, out of the lanes each was clicked in -- exactly @@ -2354,20 +2343,16 @@ fn a_colliding_set_paste_refuses_whole() { session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); - assert!( - session - .place_stream_at(10.0, &second, 0, None) - .expect("av2 is on this timeline") - ); + assert!(session + .place_stream_at(10.0, &second, 0, None) + .expect("av2 is on this timeline")); let clip0 = session.lane_clips(Lane::V1)[0]; let clip1 = session.lane_clips(Lane::V1)[1]; let v2 = session.add_lane(LaneKind::Video); - assert!( - session - .place_stream_at(20.0, &path, 0, Some(v2)) - .expect("test_av.mp4 is on this timeline") - ); + assert!(session + .place_stream_at(20.0, &path, 0, Some(v2)) + .expect("test_av.mp4 is on this timeline")); let clip_c = session.lane_clips(v2)[0]; let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)]; @@ -2422,11 +2407,9 @@ fn a_grouped_clip_on_an_added_lane_closes_its_hole_with_its_caption() { let (mut session, sub_lane) = with_subtitle_lane(); let v2 = session.add_lane(LaneKind::Video); let path = session.sources()[0].path.clone(); - assert!( - session - .place_stream_at(0.0, &path, 0, Some(v2)) - .expect("its own file is on this timeline") - ); + assert!(session + .place_stream_at(0.0, &path, 0, Some(v2)) + .expect("its own file is on this timeline")); session .place_sub(sub_lane, 0, one_second(0)) .expect("the caption goes down"); @@ -2722,6 +2705,35 @@ fn escape_closes_a_card_before_it_can_ever_reach_deselect() { } } +/// A refused split is not an edit, so it may not drop the clip in hand: the +/// refused stroke is worded ("NOTHING TO SPLIT — the playhead is already on a +/// cut") and the pick is still what the next `x`, `delete` or clip-menu row acts +/// on. The clear rides the door's own answer, the way [`Player::regroup`]'s +/// always has -- a split that happened is the other way round: the seam it +/// leaves renumbers the lane, so a pick kept across it names the wrong clip. +/// +/// A scan and not a drive: `self.selected` lives on `Player`, which needs a gpui +/// `Context` this binary has no harness for. The state itself is driven in +/// `the_playhead_actions_still_work_with_a_caption_marked`, which holds the real +/// `cut_at` refusal this gate is about. +#[test] +fn a_refused_split_keeps_the_clip_in_hand() { + let body = fn_body("cut"); + let (before, after) = body + .split_once("if cut {") + .expect("the split door no longer gates anything on its own answer"); + assert!( + !before.contains("self.selected.clear()"), + "the split drops the selection before it knows the cut happened, so a \ + refused split leaves the user with nothing picked and nothing told" + ); + assert!( + after.contains("self.selected.clear()"), + "a split that happened no longer drops the selection, so the mark names \ + a different clip on the far side of the seam" + ); +} + /// The other half: with nothing on screen to claim the key, bare escape falls /// all the way through to `Player::act`, whose `ActionId::Deselect` arm is /// the one place `self.selected` is emptied by a bare stroke rather than by @@ -2802,13 +2814,21 @@ fn every_verb_the_spine_carried_is_a_right_click_row() { // Every menu is a list of actions the keyboard already reaches, so every // row can wear its chord (DESIGN §4): a row built here out of an id the // registry never files would print an empty column. - for action in MENU_ITEMS.into_iter().chain(BENCH_ITEMS).chain(heads.iter().copied()) { + for action in MENU_ITEMS + .into_iter() + .chain(BENCH_ITEMS) + .chain(heads.iter().copied()) + { assert!( ActionId::ALL.contains(&action), "{action:?} is a menu row and not a registered action" ); } - for list in [MENU_ITEMS.to_vec(), BENCH_ITEMS.to_vec(), lane_items(Lane::A1)] { + for list in [ + MENU_ITEMS.to_vec(), + BENCH_ITEMS.to_vec(), + lane_items(Lane::A1), + ] { let first = list.iter().position(|&a| destructive(a)); if let Some(first) = first { assert!(