forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBfbc29d1Tahinli2 months ago972 commits

view.rs1137 lines, 46.8 KiBHistoryRawDownload
1//! Where a moment is drawn: drops and snaps, the zoom and the scroll, the
2//! paths a file is written to, and the strokes the handler answers.
3
4use super::*;
5
6/// The preview's one cached cue picture is keyed by the *cue* and not only by
7/// where it happens to sit: a lane and a start microsecond are not an identity --
8/// lift a bitmap caption off a lane, drop another track's caption at the same
9/// frame, and a key of those two matched the cache, painting the picture of the
10/// cue that is gone over the one that is up. The picture's own allocation is the
11/// rest of the key, and an identical repeat still hits, which is the whole cache.
12#[test]
13fn a_cached_cue_picture_is_keyed_by_the_cue_not_only_its_moment() {
14 use crate::ui::preview::sub_image_key;
15 let (lane, other) = (Lane::S1, Lane::A1);
16 // Two cues that share the lane and the start, and nothing else: one lifted,
17 // one placed at the same frame.
18 let a = sub_image_key(lane, 1_000_000, 3_000_000, 0x1000);
19 let b = sub_image_key(lane, 1_000_000, 3_000_000, 0x2000);
20 assert_ne!(
21 a, b,
22 "two different cues at one moment on one lane are one cache key again, so \
23 the second paints the first's picture"
24 );
25 // The same cue repainted: still a hit.
26 assert_eq!(
27 a,
28 sub_image_key(lane, 1_000_000, 3_000_000, 0x1000),
29 "the cache misses on every repaint of the same cue, so it decodes an 8 MB \
30 display set per frame"
31 );
32 // The same picture recut over the same start is a different cue.
33 assert_ne!(
34 a,
35 sub_image_key(lane, 1_000_000, 2_500_000, 0x1000),
36 "a cue's own end is no part of the key, so a recut cue serves the old window"
37 );
38 // And the other half of the old key still holds: the four PGS tracks of a
39 // remux start at the same microsecond, so the lane separates them.
40 assert_ne!(
41 a,
42 sub_image_key(other, 1_000_000, 3_000_000, 0x1000),
43 "the lane is no longer part of the key, so a lane's eye shut leaves the \
44 other lane's caption on screen"
45 );
46 // And the door builds its key this way, out of the cue's own picture: the
47 // cache is only keyed by the cue while the lookup goes through this
48 // constructor, and a test of the constructor alone would pass with the door
49 // still keying on `(lane, start_us)`.
50 let preview_rs = src_text("ui/preview.rs");
51 assert!(
52 preview_rs.contains(
53 "let key = sub_image_key(lane, start_us, end_us, Arc::as_ptr(image) as usize);"
54 ),
55 "the cue picture is cached under a key that is not the cue's own"
56 );
57 assert!(
58 preview_rs.contains("*up == key"),
59 "the cache no longer compares the key it built"
60 );
61}
62
63/// What a drop reads: the frame under the pointer, through the same scale
64/// the boxes are drawn through. Zoomed in, the same pixel is a different
65/// frame -- which is the whole reason `Player::frame_under` goes through
66/// [`Scale`] rather than through the duration alone.
67#[test]
68fn a_drop_reads_the_frame_under_the_pointer_at_every_zoom() {
69 // A 200 px bed inset by the panel's padding, 10 seconds at 30 fps.
70 let bed: Bounds<Pixels> = Bounds {
71 origin: point(px(12.), px(400.)),
72 size: size(px(200.), px(6.)),
73 };
74 let fps = 30.;
75 // The frame a pointer at window `x` names, exactly as `frame_under`
76 // composes it.
77 let under = |scale: Scale, x: f32| frame_at(scale.time_at(px_along(px(x), bed)), fps);
78
79 // The whole 10 s timeline across the 200 px bed: 20 px to the second,
80 // so halfway along is frame 150.
81 let fit = Scale {
82 pps: 20.,
83 start: 0.,
84 };
85 assert_eq!(under(fit, 12.), 0);
86 assert_eq!(under(fit, 112.), 150);
87 assert_eq!(under(fit, 212.), 300);
88
89 // Four times in, starting at second 5: the same middle pixel is now the
90 // frame in the middle of seconds 5..7.5, and the left edge is not 0.
91 let zoomed = Scale {
92 pps: 80.,
93 start: 5.,
94 };
95 assert_eq!(under(zoomed, 12.), 150);
96 assert_eq!(under(zoomed, 112.), 187);
97 assert_eq!(under(zoomed, 212.), 225);
98 // ...and a pointer that slid off either end of the bed names an end of
99 // the bed, never a pixel outside it.
100 assert_eq!(under(zoomed, 0.), 150);
101 assert_eq!(under(fit, 9999.), 300);
102}
103
104/// The snap: a clip let go a few frames off a neighbour's edge lands *on*
105/// it, by whichever of its own ends is nearer, and a clip let go in open bed
106/// stays exactly where the hand left it.
107#[test]
108fn a_dropped_clip_snaps_to_the_edges_worth_landing_on() {
109 // A neighbour covering [100, 160) and the playhead at 300.
110 let marks = [100, 160, 300, 0];
111 // Head a frame short of the neighbour's tail: laid end to end with it.
112 assert_eq!(snapped(158, 40, 4, &marks), 160);
113 // Tail a frame into its head: pulled back so the two meet exactly.
114 assert_eq!(snapped(62, 40, 4, &marks), 60);
115 // The playhead is an edge like any other.
116 assert_eq!(snapped(298, 40, 4, &marks), 300);
117 // Outside the tolerance nothing moves -- a gap the hand meant to leave
118 // is a gap.
119 assert_eq!(snapped(150, 40, 4, &marks), 150);
120 // No tolerance at all (zoomed right in, where a few pixels are worth
121 // less than a frame) is no snap: single frames are placed by hand.
122 assert_eq!(snapped(158, 40, 0, &marks), 158);
123 // The nearer edge wins when two are in reach.
124 assert_eq!(snapped(101, 40, 8, &marks), 100);
125 // ...and a mark closer to the head than `len` cannot pull the clip to a
126 // negative start.
127 assert_eq!(snapped(2, 40, 4, &marks), 0);
128}
129
130/// The shadow a drag draws and the drop that commits are one answer: both
131/// ask [`landing`], so the box seen in flight is the box the release leaves
132/// behind. What this pins down is the composition around the snap -- the
133/// grab offset comes off *before* the magnet, or a clip taken by its tail
134/// would land a boxful late.
135#[test]
136fn a_ghost_and_a_drop_are_one_landing() {
137 // A neighbour covering [100, 160), the playhead at 300, and a 40 frame
138 // clip taken hold of 12 frames in.
139 let marks = [100, 160, 300, 0];
140 let (len, grab, tol) = (40, 12, 4);
141 // Pointer at frame 170: the head is 12 frames behind it, at 158, which
142 // is a frame short of the neighbour's tail -- so both the ghost and the
143 // drop say 160, and the line stands on the mark that pulled it.
144 assert_eq!(landing(170, grab, len, true, tol, &marks), (160, Some(160)));
145 // Without the grab taken off first, the same pointer would land the
146 // box at 170 and no mark would be in reach: the offset is not cosmetic.
147 assert_eq!(landing(170, 0, len, true, tol, &marks), (170, None));
148 // A library row carries no grab and no length the engine has measured,
149 // which is how `Player::place_frame` asks: only its head lands, on the
150 // playhead here.
151 assert_eq!(landing(298, 0, 0, true, tol, &marks), (300, Some(300)));
152 // The magnet off, ghost and drop agree on the raw frame and no line is
153 // drawn -- the frame-by-frame placement the switch is for.
154 assert_eq!(landing(170, grab, len, false, tol, &marks), (158, None));
155 // A pointer nearer the bed's start than the hand is into the box cannot
156 // pull a head below zero.
157 assert_eq!(landing(3, grab, len, true, tol, &marks), (0, Some(0)));
158}
159
160/// Which lanes tint that shadow as refused: the two kinds of file a lane
161/// cannot hold, in the words the release would say them in -- one rule, so
162/// what is shown as impossible is exactly what is refused.
163#[test]
164fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
165 let (video, audio) = (Lane::V1, Lane::A1);
166 let sound = Path::new("/media/take.mp3");
167 let still = Path::new("/media/card.png");
168 let movie = Path::new("/media/take.mp4");
169 assert_eq!(
170 lane_refuses(sound, video, false).as_deref(),
171 Some("NOT ON V1 — take.mp3 has no picture")
172 );
173 assert_eq!(
174 lane_refuses(still, audio, true).as_deref(),
175 Some("NOT ON A1 — card.png is a still image")
176 );
177 // ...and every lane a file *can* go on says nothing at all, which is a
178 // ghost drawn in the file's own colour.
179 assert_eq!(lane_refuses(sound, audio, false), None);
180 assert_eq!(lane_refuses(still, video, true), None);
181 assert_eq!(lane_refuses(movie, video, true), None);
182 // A file with a picture is not refused by an audio lane here: the
183 // engine takes its sound onto one, and the words for a video-only file
184 // are its own.
185 assert_eq!(lane_refuses(movie, audio, true), None);
186 // The extension lies and the probe corrects it: a song muxed into an
187 // `.mp4` still names a video lane refused, in the exact words the .mp3
188 // twin above got -- `has_video` is what decides it now, not the suffix.
189 assert_eq!(
190 lane_refuses(movie, video, false).as_deref(),
191 Some("NOT ON V1 — take.mp4 has no picture")
192 );
193 // ...and a subtitle lane holds none of the three: a caption comes off the
194 // Subtitles list, which is where the refusal points.
195 for (file, has_video) in [(sound, false), (still, true), (movie, true)] {
196 let why = lane_refuses(file, Lane::S1, has_video).expect("a subtitle lane takes no media");
197 assert!(why.starts_with("NOT ON S1 — "), "{why}");
198 assert!(why.contains("Subtitles list"), "{why}");
199 }
200 // How the two clocks a caption has meet, which is what a palette row's
201 // length is worked out with: a second of words at 30 fps is 30 frames,
202 // and a track shorter than one frame is still a caption to place.
203 assert_eq!(frames_of_us(1_000_000, 30.), 30);
204 assert_eq!(frames_of_us(500_000, 24.), 12);
205 assert_eq!(frames_of_us(1_000, 30.), 1);
206 assert_eq!(frames_of_us(1_000_000, 0.), 1);
207}
208
209/// Where those edges come from: every lane, not the one being dropped on --
210/// and never the clip in the hand or the half of it one track down.
211#[test]
212fn the_marks_are_every_lane_the_playhead_and_the_start() {
213 let clip = |start: u32, frames: u32, link| Clip {
214 fade_in: 0,
215 fade_out: 0,
216 transition_out: 0,
217 visualizer: 0,
218 viz_paint: 0,
219 start,
220 in_frame: 0,
221 out_frame: frames,
222 source: 0,
223 link,
224 eq: None,
225 color: None,
226 transform: None,
227 fit: Default::default(),
228 speed: Default::default(),
229 };
230 // A grouped take across two lanes at 100..160, and a lone one on the
231 // audio lane at 400..430.
232 let video = [clip(100, 60, Some(7))];
233 let audio = [clip(100, 60, Some(7)), clip(400, 30, None)];
234 let lanes: [&[Clip]; 2] = [&video, &audio];
235
236 // Nothing in the hand: both lanes' edges, the playhead, and 0.
237 let mut all = snap_marks(&lanes, None, None, 300, None);
238 all.sort_unstable();
239 assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]);
240
241 // The video half in the hand, with its group named as the caller reads it
242 // off the pick: its own edges are gone, and so are its group's on the
243 // other lane -- both boxes travel with the drag. The lone audio clip is
244 // still a target, which is the whole point: a take being carried on V1
245 // lands flush with a sound on A1.
246 let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300, None);
247 carried.sort_unstable();
248 assert_eq!(carried, [0, 300, 400, 430]);
249
250 // An index that names no clip skips nothing and still answers.
251 assert_eq!(snap_marks(&[], Some((3, 9)), None, 0, None), [0, 0]);
252}
253
254/// The line the bed draws, and the switch that turns the whole thing off.
255#[test]
256fn the_snap_names_the_mark_it_landed_on_unless_it_is_switched_off() {
257 let marks = [100, 160, 300, 0];
258 // Pulled by the tail: the clip lands at 60 and the line stands on the
259 // edge its *tail* met, 100 -- not on the head it happens to have.
260 assert_eq!(snap_cue(true, 62, 40, 4, &marks), (60, Some(100)));
261 // Pulled by the head: line and landing are the same frame.
262 assert_eq!(snap_cue(true, 158, 40, 4, &marks), (160, Some(160)));
263 // A trim carries no length, so only its own edge lands.
264 assert_eq!(snap_cue(true, 298, 0, 4, &marks), (300, Some(300)));
265 // Open bed: nothing moves and nothing is drawn.
266 assert_eq!(snap_cue(true, 200, 40, 4, &marks), (200, None));
267 // Switched off, a gesture that would have snapped lands raw and draws
268 // no line -- the frame-by-frame placement the toggle is for.
269 assert_eq!(snap_cue(false, 158, 40, 4, &marks), (158, None));
270}
271
272/// The card's rate row: every component the container states and no other,
273/// so a track the header is silent about is absent from the line rather
274/// than sitting in it as a zero.
275#[test]
276fn a_rate_row_says_only_what_the_container_stated() {
277 use crate::MediaBitrate;
278 let all = MediaBitrate {
279 total: Some(8_432_000),
280 video: Some(7_918_000),
281 audio: Some(128_000),
282 };
283 assert_eq!(
284 bitrate_detail(Some(all), 1),
285 "8.4 Mb/s · 7.9 video · 0.13 sound"
286 );
287 // A Matroska states no audio rate of its own: the sound is dropped from
288 // the line, never drawn as "0".
289 assert_eq!(
290 bitrate_detail(Some(MediaBitrate { audio: None, ..all }), 1),
291 "8.4 Mb/s · 7.9 video"
292 );
293 // A still, or anything that would not open: the probe answered, and the
294 // answer is that nobody said.
295 assert_eq!(
296 bitrate_detail(Some(MediaBitrate::default()), 0),
297 "not stated"
298 );
299 // Asked, not answered yet -- a 12 GB film's walk takes seconds.
300 assert_eq!(bitrate_detail(None, 2), "…");
301 // A dual-audio file: the number is the track that plays, and the line
302 // says so rather than letting it stand for the AC-3 beside it.
303 assert_eq!(
304 bitrate_detail(Some(all), 2),
305 "8.4 Mb/s · 7.9 video · 0.13 1 of 2"
306 );
307 // Every component of a tiny file is stated, and small: the line changes
308 // unit, so not one of them reads as the zero it is not. In megabits
309 // this file was "0.00 Mb/s · 0.00 video · 0.00 sound".
310 assert_eq!(
311 bitrate_detail(
312 Some(MediaBitrate {
313 total: Some(4_998),
314 video: Some(113),
315 audio: Some(2_400),
316 }),
317 1
318 ),
319 "5.0 kb/s · 0.11 video · 2.4 sound"
320 );
321}
322
323/// The invariant under the row above, over every rate a container can
324/// state: a component the file *does* state never renders as a zero. The
325/// probe leaves out what is unstated, so a "0.00" on this card would be it
326/// saying a track that plays is silent.
327#[test]
328fn a_stated_rate_never_renders_as_a_zero() {
329 use crate::MediaBitrate;
330 // Every decade from 1 bit a second to a 100 Mb/s master, the rounding
331 // edges of each unit switch, and every pair of them in one line: the
332 // line's unit is picked off its smallest component, so the widest
333 // spread is the one that could round the biggest away.
334 let edges: Vec<u64> = (0..12)
335 .flat_map(|e| {
336 let decade = 10_u64.pow(e);
337 [decade, decade * 4, decade * 5, decade * 9]
338 })
339 .chain([MB_FLOOR - 1, MB_FLOOR, 999_999, 4_998, 113, 2_400])
340 .collect();
341 for &small in &edges {
342 for &big in &edges {
343 let line = bitrate_detail(
344 Some(MediaBitrate {
345 total: Some(small.max(big)),
346 video: Some(big),
347 audio: Some(small),
348 }),
349 2,
350 );
351 for number in line
352 .split(" · ")
353 .filter_map(|part| part.split(' ').next())
354 .filter_map(|n| n.parse::<f64>().ok())
355 {
356 assert!(
357 number > 0.,
358 "{small}/{big} bits a second rendered as {line:?}"
359 );
360 }
361 }
362 }
363}
364
365#[test]
366fn timecode_counts_frames_inside_the_second() {
367 assert_eq!(timecode(0., 30.), "00:00:00:00");
368 assert_eq!(timecode(-1., 30.), "00:00:00:00"); // clamped, never negative
369 assert_eq!(timecode(4.9667, 30.), "00:00:04:29"); // last frame of a 5 s clip
370 assert_eq!(timecode(5., 30.), "00:00:05:00");
371 assert_eq!(timecode(3661.5, 30.), "01:01:01:15");
372 // Rounding must not spill into a frame the second does not have.
373 assert_eq!(timecode(1. - f64::EPSILON, 30.), "00:00:00:29");
374 assert_eq!(timecode(0.999, 29.97), "00:00:00:29");
375}
376
377#[test]
378fn scrub_seeks_only_on_a_new_frame_and_only_every_100ms() {
379 let (slow, fast) = (Duration::from_millis(100), Duration::from_millis(99));
380 // Both halves must hold: a moved pointer that has not crossed a frame
381 // boundary would reopen the decoder for the same picture.
382 assert!(scrub_due(31, 30, slow));
383 assert!(!scrub_due(30, 30, slow));
384 assert!(!scrub_due(31, 30, fast));
385 assert!(!scrub_due(30, 30, fast));
386 // Exactly at the gap counts, and a long stall never blocks.
387 assert!(scrub_due(1, 0, Duration::from_secs(9)));
388}
389
390#[test]
391fn the_picture_is_restarted_only_when_it_is_really_behind_and_not_twice() {
392 // A quantum's worth of lateness is what every playing frame has; only a
393 // gap an eye reads as out of sync answers with a reopen.
394 assert!(!should_resync(0., None));
395 assert!(!should_resync(LATE_RESYNC, None));
396 assert!(should_resync(LATE_RESYNC + 0.1, None));
397 // ...and a decoder that is still behind right after a restart -- the
398 // usual case, since it was too slow to begin with -- waits out the gap
399 // instead of reopening at every repaint.
400 assert!(!should_resync(9., Some(Instant::now())));
401 assert!(should_resync(
402 9.,
403 Some(Instant::now() - RESYNC_GAP - Duration::from_millis(1))
404 ));
405}
406
407#[test]
408fn export_lands_beside_the_source_and_never_on_it() {
409 // The whole point: the export of an .mp4 is never that .mp4.
410 assert_eq!(
411 export_path("assets/test_baseline.mp4"),
412 std::path::Path::new("assets/test_baseline.export.mp4")
413 );
414 // A second export of an export is still not its own source.
415 assert_eq!(
416 export_path("a.export.mp4"),
417 std::path::Path::new("a.export.export.mp4")
418 );
419 // Extensionless and dotted-directory names keep the directory intact.
420 assert_eq!(export_path("clip"), std::path::Path::new("clip.export.mp4"));
421 assert_eq!(
422 export_path("/v.1/clip.MP4"),
423 std::path::Path::new("/v.1/clip.export.mp4")
424 );
425}
426
427#[test]
428fn the_first_save_lands_beside_the_media() {
429 assert_eq!(
430 project_path("assets/test_av.mp4"),
431 std::path::Path::new("assets/test_av.edith")
432 );
433 // The same rule an export follows: only the last extension moves.
434 assert_eq!(
435 project_path("a.export.mp4"),
436 std::path::Path::new("a.export.edith")
437 );
438 assert_eq!(project_path("clip"), std::path::Path::new("clip.edith"));
439 // Saving a loaded project writes the file it came from, not a second.
440 assert_eq!(project_path("a.edith"), std::path::Path::new("a.edith"));
441}
442
443#[test]
444fn only_an_exact_edith_extension_is_a_project() {
445 let p = std::path::Path::new;
446 assert!(is_project(p("a.edith")));
447 // A dotted directory must not decide it -- the file name does.
448 assert!(is_project(p("/v.mp4/a.edith")));
449 assert!(!is_project(p("a.mp4")));
450 assert!(!is_project(p("/v.edith/a.mp4")));
451 // Exactly what `save_project` writes: a dropped `.EDITH` goes to the
452 // demuxer and is refused there, not parsed as a project.
453 assert!(!is_project(p("a.EDITH")));
454 // An extension, never a bare name.
455 assert!(!is_project(p("edith")));
456 assert!(!is_project(p("a.edith.mp4")));
457}
458
459/// The keys menu is the registry drawn, so a *bindable* stroke cannot go
460/// missing from it by construction. The strokes the modal cards read for
461/// themselves are the ones that could: this reads the key handler's own
462/// source and fails on any key it answers to that the menu never mentions.
463#[test]
464fn no_stroke_is_missing_from_the_keys_menu() {
465 use keymap::{ActionId, Keymap};
466 // Every file the window is written in -- the handler, and the helpers
467 // it asks, wherever they have been moved to. The tests below compare
468 // keys too, and are not shortcuts.
469 let handler = ui_source();
470 let handler = handler.as_str();
471 let keymap = Keymap::defaults();
472 let listed = |key: &str| {
473 let pretty = keymap::Chord {
474 key: key.to_string(),
475 ctrl: false,
476 }
477 .pretty();
478 keymap.lookup(key, false).is_some() || keymap::FIXED.iter().any(|f| f.chord == pretty)
479 };
480 let mut compared = 0;
481 for (at, needle) in handler.match_indices("key == ") {
482 let rest = &handler[at + needle.len()..];
483 let key = match rest.strip_prefix('"') {
484 Some(literal) => literal[..literal.find('"').expect("unterminated key")].to_string(),
485 // A named constant: the escape the cards get out by.
486 None if rest.starts_with("ESCAPE") => crate::ESCAPE.to_string(),
487 None => panic!("a key compared against something this cannot read: {rest:.20}"),
488 };
489 assert!(
490 listed(&key),
491 "the handler answers to {key:?} and the keys menu never says so"
492 );
493 compared += 1;
494 }
495 // The scan is only a guard while it still finds the comparisons: a
496 // rewrite that spells them differently must come back here.
497 assert!(
498 compared >= 4,
499 "the key comparisons moved; this scan is blind"
500 );
501 // The one branch that is not a comparison -- any digit is a bitrate.
502 assert!(handler.contains("key.parse::<u32>()"));
503 assert!(keymap::FIXED.iter().any(|f| f.chord == "0–9"));
504 // And every entry of both halves lands under a heading the menu draws.
505 for action in ActionId::ALL {
506 assert!(keymap::Category::ALL.contains(&action.category()));
507 }
508 for fixed in keymap::FIXED.iter() {
509 assert!(keymap::Category::ALL.contains(&fixed.category));
510 }
511}
512
513/// The mapping the whole panel is drawn and clicked through: a moment goes
514/// to a pixel on the bed and comes back the same moment, at every zoom.
515#[test]
516fn a_moment_and_the_place_it_is_drawn_are_the_same_at_every_zoom() {
517 let duration = 20.;
518 // The fit, which is the only scale the content's own length picks: 20 s
519 // across a 200 px bed is 10 px to the second, and a 5 s clip is a
520 // quarter of the bed -- the answer the fractional view gave for it.
521 let fit = test_view(Scale::default(), duration).fit();
522 assert_eq!(fit.pps, 10.);
523 assert_eq!(fit.width_px(5.), TEST_BED * 0.25);
524 for t in [0., 5., 12.5, 20.] {
525 assert_eq!(fit.px_at(t), (t / duration) as f32 * TEST_BED, "fit at {t}");
526 }
527 for scale in [
528 fit,
529 Scale {
530 pps: 20.,
531 start: 4.,
532 },
533 Scale {
534 pps: 80.,
535 start: 12.5,
536 },
537 Scale {
538 pps: 375.,
539 start: 19.,
540 },
541 ] {
542 let scale = test_view(scale, duration).settled();
543 for x in [0., 50., 100., TEST_BED] {
544 let at = scale.time_at(x);
545 assert!(
546 (f64::from(scale.px_at(at)) - f64::from(x)).abs() < 1e-3,
547 "{scale:?} round trip at {x}"
548 );
549 }
550 // A stretch as long as what is on the bed is as wide as the bed.
551 assert!(
552 (f64::from(scale.width_px(test_view(scale, duration).span())) - f64::from(TEST_BED))
553 .abs()
554 < 1e-3,
555 "{scale:?} spans the bed"
556 );
557 }
558}
559
560/// The rule that makes a zoom usable: whatever was under the anchor is
561/// still under it afterwards -- the playhead for a key, the pointer for a
562/// ctrl+wheel.
563#[test]
564fn a_zoom_leaves_the_anchor_where_it_was_on_screen() {
565 let duration = 20.;
566 let mut scale = test_view(Scale::default(), duration).settled();
567 // The same three points along the bed the fractional view held: a half,
568 // a quarter and nine tenths of 200 px.
569 for anchor in [100f32, 50., 180.] {
570 // Well past the zoom-in stop: the anchor holds at the clamp too,
571 // which is where it used to slide (the clamp came after the offset).
572 for _ in 0..30 {
573 let at = scale.time_at(anchor);
574 let view = test_view(scale, duration);
575 let zoomed = view.zoomed(ZOOM_STEP, anchor);
576 // Only where the anchor is not pinned by an edge of the
577 // timeline: a view already against an end cannot slide further.
578 let span = test_view(zoomed, duration).span();
579 let pinned = zoomed.start <= 0. || zoomed.start + span >= duration;
580 if !pinned {
581 assert!(
582 (f64::from(zoomed.px_at(at)) - f64::from(anchor)).abs() < 1e-3,
583 "{at} moved: {scale:?} -> {zoomed:?}"
584 );
585 }
586 assert!(zoomed.pps >= scale.pps, "and it did zoom in");
587 scale = zoomed;
588 }
589 }
590}
591
592/// Both stops. In is [`ZOOM_MIN_FRAMES`] across the bed; out, on a timeline
593/// far too short to be worth widening to, is a pixel to the second -- so a
594/// short import can be zoomed out of, a long one zoomed into, and neither
595/// can scroll off an end.
596#[test]
597fn zoom_stops_at_a_bedful_of_time_and_at_a_handful_of_frames() {
598 let (duration, fps) = (20., 30.);
599 let mut scale = Scale::default();
600 for _ in 0..200 {
601 scale = test_view(scale, duration).zoomed(1. / ZOOM_STEP, 100.);
602 }
603 assert!(
604 (test_view(scale, duration).span() - f64::from(TEST_BED) / PPS_MIN).abs() < 1e-6,
605 "widest is a pixel to the second, not the 20 s that happen to be on it"
606 );
607 for _ in 0..200 {
608 scale = test_view(scale, duration).zoomed(ZOOM_STEP, 100.);
609 }
610 assert_eq!(
611 (test_view(scale, duration).span() * fps).round(),
612 ZOOM_MIN_FRAMES,
613 "tightest is a handful of frames"
614 );
615 // Against the far end, the slice still ends at the last frame.
616 let end = test_view(
617 Scale {
618 start: 1e6,
619 ..scale
620 },
621 duration,
622 );
623 let end = (end.settled(), end.span());
624 assert!((end.0.start + end.1 - duration).abs() < 1e-9);
625 assert_eq!(
626 test_view(
627 Scale {
628 start: -5.,
629 ..scale
630 },
631 duration
632 )
633 .settled()
634 .start,
635 0.
636 );
637 // The dead zone the fractional view had: a timeline of a handful of
638 // frames could not be zoomed at all, because its own length was the
639 // floor *and* the ceiling. Both keys work on it now.
640 let tiny = test_view(Scale::default(), 0.1);
641 assert!(tiny.zoomed(ZOOM_STEP, 100.).pps > PPS_DEFAULT);
642 assert!(tiny.zoomed(1. / ZOOM_STEP, 100.).pps < PPS_DEFAULT);
643 // A timeline with no length at all divides by nothing and scrolls
644 // nowhere; the fit of one keeps the scale it had.
645 let empty = test_view(Scale::default(), 0.);
646 assert_eq!(empty.settled(), Scale::default());
647 assert_eq!(empty.fit(), Scale::default());
648 assert_eq!(Scale::default().px_at(0.), 0.);
649 // A bed that was never painted clamps nothing -- there is nothing to
650 // clamp against, and a zoom must survive the frame before the probe.
651 let unpainted = View {
652 bed: 0.,
653 ..test_view(
654 Scale {
655 pps: 4e6,
656 start: 3.,
657 },
658 duration,
659 )
660 };
661 assert_eq!(unpainted.settled().pps, 4e6);
662 assert_eq!(unpainted.following(19.), unpainted.scale);
663}
664
665/// The bug a fixed far stop was: two two-and-a-half hour clips are five
666/// hours of timeline, longer than any stop measured in hours, so the end of
667/// the second one could not be brought on screen by any zoom. The stop is
668/// the timeline's own length now, so it can.
669#[test]
670fn zooming_out_reaches_the_end_of_a_timeline_however_long_it_is() {
671 let bed = 900.;
672 let view = |scale: Scale, duration: f64| View {
673 scale,
674 bed,
675 duration,
676 fps: 30.,
677 };
678 // As far out as the keys go, from the scale a fresh project is drawn at.
679 let out = |duration: f64| {
680 let mut scale = Scale::default();
681 for _ in 0..400 {
682 scale = view(scale, duration).zoomed(1. / ZOOM_STEP, 0.);
683 }
684 scale
685 };
686 let five_hours = 2. * 2.5 * 3600.;
687 let wide = out(five_hours);
688 // The whole five hours is on the bed, the last frame drawn inside the
689 // window rather than against its edge.
690 assert_eq!(wide.start, 0.);
691 let end = wide.px_at(five_hours);
692 assert!(
693 end < bed,
694 "the end of the timeline is off the bed at {end} px"
695 );
696 assert!(end > bed * 0.9, "and not shrunk into a corner: {end} px");
697 assert!(
698 (view(wide, five_hours).span() - five_hours * ZOOM_OUT_MARGIN).abs() < 1e-6,
699 "the far stop is the timeline plus its margin"
700 );
701 // Zooming back in still reaches the frame stop on a timeline that long:
702 // the far stop moving does not drag the near one with it.
703 let mut scale = wide;
704 for _ in 0..400 {
705 scale = view(scale, five_hours).zoomed(ZOOM_STEP, 0.);
706 }
707 assert_eq!(
708 (view(scale, five_hours).span() * 30.).round(),
709 ZOOM_MIN_FRAMES
710 );
711 // And a ten second project is not zoomed out to four hours of empty
712 // bed: short of a pixel to the second its own length is not worth
713 // widening to, and that is 900 s of bed, not 14400.
714 assert!((view(out(10.), 10.).span() - f64::from(bed) / PPS_MIN).abs() < 1e-6);
715 // Whatever the length, the resting scale is nobody's content: the width
716 // invariant, which a far stop measured off the content would break.
717 assert_eq!(view(Scale::default(), 10.).settled(), Scale::default());
718 assert_eq!(
719 view(Scale::default(), five_hours).settled(),
720 Scale::default()
721 );
722 // Shrinking the timeline pulls a fully zoomed out view in with it --
723 // what was showing all of the timeline still shows all of it.
724 let shrunk = view(wide, 1800.).settled();
725 assert!((view(shrunk, 1800.).span() - 1800. * ZOOM_OUT_MARGIN).abs() < 1e-6);
726 assert!(shrunk.px_at(1800.) < bed);
727 // Growing it does not: a scale the user zoomed to is still legal, and
728 // the stop it stopped at is one press further out.
729 assert_eq!(view(wide, 2. * five_hours).settled().pps, wide.pps);
730 assert!(view(wide, 2. * five_hours).zoomed(1. / ZOOM_STEP, 0.).pps < wide.pps);
731}
732
733/// The bare wheel's own move: the view slides along the timeline, what is
734/// drawn where slides with it, the scale never changes, and both ends stop
735/// against the content rather than scrolling it off the bed.
736#[test]
737fn a_scroll_slides_the_view_without_zooming_it() {
738 let duration = 60.;
739 // Zoomed in far enough that there is somewhere to scroll to: 10 s of a
740 // 60 s timeline on the bed.
741 let start = test_view(
742 Scale {
743 pps: f64::from(TEST_BED) / 10.,
744 start: 0.,
745 },
746 duration,
747 )
748 .settled();
749 let notch = TEST_BED * SCROLL_NOTCH_SHARE;
750 let on = test_view(start, duration).scrolled(notch);
751 // A tenth of the bed later, and drawn a tenth of the bed to the left --
752 // the two halves of one move.
753 assert_eq!(on.pps, start.pps, "a scroll is not a zoom");
754 assert!(
755 (on.start - (start.start + 1.)).abs() < 1e-9,
756 "one notch is a tenth of the 10 s on the bed: {on:?}"
757 );
758 assert!(
759 (f64::from(start.px_at(20.) - on.px_at(20.)) - f64::from(notch)).abs() < 1e-3,
760 "and what was drawn moved with it: {on:?}"
761 );
762 // Back the other way, from the same place, is the same distance.
763 let back = test_view(on, duration).scrolled(-notch);
764 assert!((back.start - start.start).abs() < 1e-9, "{back:?}");
765 // Neither end can be scrolled off: the head stops at zero, and the tail
766 // stops with the last frame on the bed -- the clamp is the timeline's
767 // own length, not a number.
768 let mut scale = start;
769 for _ in 0..200 {
770 scale = test_view(scale, duration).scrolled(notch);
771 }
772 assert_eq!(scale.pps, start.pps);
773 assert!(
774 (scale.start - (duration - 10.)).abs() < 1e-6,
775 "the tail stops with the end on the bed: {scale:?}"
776 );
777 for _ in 0..200 {
778 scale = test_view(scale, duration).scrolled(-notch);
779 }
780 assert_eq!(scale.start, 0., "and the head stops at the head: {scale:?}");
781 // A view already showing all of it has nowhere to go.
782 let whole = test_view(Scale::default(), duration).fit();
783 assert_eq!(test_view(whole, duration).scrolled(notch), whole);
784}
785
786/// What makes a zoomed timeline follow the playing head: off the bed at
787/// either end pulls the view onto it, and on the bed it never moves -- a
788/// view that jumped every frame would be unreadable.
789#[test]
790fn the_view_follows_a_playhead_that_runs_off_the_bed() {
791 let duration = 20.;
792 // 5 s on a 200 px bed: 40 px to the second, starting at second 5.
793 let view = test_view(
794 Scale {
795 pps: 40.,
796 start: 5.,
797 },
798 duration,
799 );
800 let scale = view.settled();
801 assert_eq!(view.span(), 5.);
802 // Inside: untouched, whichever part of the slice it is in.
803 for at in [5., 7.5, 10.] {
804 assert_eq!(view.following(at), scale, "{at} is on the bed");
805 }
806 // Past the right edge, as playback does it: the head comes back on the
807 // bed, and the scale is not changed by the scroll.
808 let moved = view.following(12.);
809 assert_eq!(moved.pps, scale.pps);
810 assert!(moved.start > scale.start, "scrolled forward");
811 assert!(
812 moved.px_at(12.) > 0. && moved.px_at(12.) < TEST_BED,
813 "and the playhead is on screen"
814 );
815 // A seek back behind the slice does the same the other way.
816 let back = view.following(1.);
817 assert!(back.start < scale.start);
818 assert!(back.px_at(1.) >= 0.);
819 // With the whole timeline on the bed there is nothing to follow.
820 let whole = test_view(Scale::default(), duration);
821 let fit = whole.fit();
822 for at in [0., 10., 20.] {
823 assert_eq!(
824 test_view(fit, duration).following(at),
825 fit,
826 "the fit never scrolls"
827 );
828 }
829}
830
831/// The wheel during playback. A scroll away from the playing head used to
832/// be undone by the follow on the very next frame -- with a second, longer
833/// media on the timeline making it scrollable at all, one notch in five
834/// reached the screen and the wheel looked dead. The hand keeps the view
835/// now, and the follow takes it back by itself when the head runs into what
836/// the hand is looking at.
837#[test]
838fn a_scroll_during_playback_wins_until_the_head_catches_up() {
839 let duration = 80.;
840 let mut scale = test_view(
841 Scale {
842 pps: 40.,
843 start: 0.,
844 },
845 duration,
846 )
847 .settled();
848 // The render's arbitration, in the two lines it is there: a panned view
849 // is left where the hand put it, and the pan ends where the head is
850 // back on the bed.
851 let frame = |scale: Scale, panned: &mut bool, at: f64| {
852 let scale = match *panned {
853 true => test_view(scale, duration).settled(),
854 false => test_view(scale, duration).following(at),
855 };
856 if *panned && test_view(scale, duration).shows(at) {
857 *panned = false;
858 }
859 scale
860 };
861 // Playing at second one, five notches of the wheel: every one of them
862 // moves the view, and none is taken back by the head being off the bed.
863 let notch = f64::from(TEST_BED * SCROLL_NOTCH_SHARE);
864 let mut panned = false;
865 for n in 1..=5 {
866 scale = test_view(scale, duration).scrolled(TEST_BED * SCROLL_NOTCH_SHARE);
867 panned = true;
868 scale = frame(scale, &mut panned, 1.);
869 // ...and the pan is only *held* while the head is off the bed: the
870 // first notches still show it, so the follow has the view back for
871 // free and would not have moved anything anyway.
872 assert_eq!(panned, scale.start > 1., "held while the head is off");
873 assert!(
874 (scale.start - notch * f64::from(n) / 40.).abs() < 1e-6,
875 "notch {n} reached the screen: {scale:?}"
876 );
877 }
878 // The head runs into it: the pan is given back with nothing pressed...
879 let span = test_view(scale, duration).span();
880 let start = frame(scale, &mut panned, scale.start + span / 2.).start;
881 assert!(!panned, "the follow has the view back");
882 assert_eq!(start, scale.start, "and it did not jump to take it");
883 // ...and the next head that runs off the bed pulls the view again.
884 let ran_off = frame(scale, &mut panned, start + span + 1.);
885 assert!(
886 ran_off.start > start,
887 "the follow follows again: {ran_off:?}"
888 );
889 // A paused hand is untouched by any of this: with no follow asking,
890 // `shows` is the only thing the pan is ever released by.
891 assert!(test_view(scale, duration).shows(scale.start));
892 assert!(!test_view(scale, duration).shows(scale.start + span + 0.5));
893}
894
895/// The bug this mapping exists for: the first import used to fill the whole
896/// track whatever it was, because the bed *was* the timeline -- so a 5 s
897/// clip was 100% of the lane, zooming out did nothing, and adding a second
898/// clip silently halved the first one's box.
899#[test]
900fn a_clip_is_drawn_the_same_width_whatever_else_is_on_the_timeline() {
901 let bed = 900.;
902 let of = |duration: f64| View {
903 scale: Scale::default(),
904 bed,
905 duration,
906 fps: 30.,
907 };
908 // One 5 s import, then a second clip after it: 20 s of timeline where
909 // there were 5, and the first box has not moved or narrowed.
910 let (alone, joined) = (of(5.).settled(), of(20.).settled());
911 assert_eq!(alone, joined);
912 assert_eq!(alone.width_px(5.), joined.width_px(5.));
913 assert_eq!(joined.px_at(5.), alone.width_px(5.));
914 // And it does not fill the track: a short clip reads as short.
915 assert!(
916 alone.width_px(5.) < bed / 2.,
917 "5 s at {} px/s is {} px of a {bed} px bed",
918 alone.pps,
919 alone.width_px(5.)
920 );
921 // Zooming out visibly shrinks it, however short the timeline is -- the
922 // press that used to be a no-op.
923 let out = of(5.).zoomed(1. / ZOOM_STEP, 0.);
924 assert!(
925 out.width_px(5.) < alone.width_px(5.),
926 "{} px is not smaller than {} px",
927 out.width_px(5.),
928 alone.width_px(5.)
929 );
930 // The way back to "the whole timeline across the bed" is still one key.
931 assert_eq!(of(5.).fit().width_px(5.), bed);
932}
933
934/// What the zoom button says: how much timeline is on the bed, in a unit
935/// that tells two zooms apart.
936#[test]
937fn the_zoom_button_says_how_much_is_on_the_bed() {
938 // A frame of quiet at 60 fps, which the silence card says out loud.
939 assert_eq!(secs_label(1. / 60.), "0.02s");
940 assert_eq!(secs_label(4.5), "4.5s");
941}
942
943/// Keyboard focus v1 (`ui::stance::{Surface, next_surface, is_focus_cycle_key}`):
944/// Tab walks dock -> bench -> inspector -> dock, wrapping; Shift-Tab walks
945/// it backward. No gpui window harness exists in this crate to drive a real
946/// `KeyDownEvent` through -- this exercises the exact pure function every
947/// surface's `on_key_down` calls, which is where the cycle order actually
948/// lives.
949#[test]
950fn tab_cycles_dock_bench_inspector_and_wraps() {
951 use crate::ui::stance::{next_surface, Surface};
952
953 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);
954 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);
955 assert_eq!(next_surface(Surface::Inspector, false), Surface::Dock);
956
957 // Shift-Tab is the exact reverse at every step.
958 assert_eq!(next_surface(Surface::Dock, true), Surface::Inspector);
959 assert_eq!(next_surface(Surface::Inspector, true), Surface::Bench);
960 assert_eq!(next_surface(Surface::Bench, true), Surface::Dock);
961}
962
963/// The defect this closes: the dock mounts only one of its two tabs at a
964/// time (`dock_stance::render`'s `match src_active`), so focusing
965/// `focus_dock`/`focus_inspector` while the other tab is showing lands on a
966/// handle with no tree node -- gpui then dispatches no key listener at all,
967/// keyboard input is dead until a mouse click. `Player::focus_surface`
968/// (`ui::stance.rs`) flips the tab first via this pure decision so the
969/// surface being entered is always the one mounted.
970#[test]
971fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() {
972 use crate::ui::stance::{surface_wants_src_active, Surface};
973
974 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));
975 assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false));
976 // Bench has no dock tab of its own -- entering it must not disturb
977 // whichever tab the dock was last left on.
978 assert_eq!(surface_wants_src_active(Surface::Bench), None);
979}
980
981/// The root fallback guarantee (main.rs:1054's "every keybind hangs off the
982/// root FocusHandle"): a surface's own `on_key_down` answers Tab/Shift-Tab
983/// and nothing else -- `cx.stop_propagation()` is only ever reached from
984/// that one branch (`ui::stance::is_focus_cycle_key`), so every other key,
985/// still-pressed while a surface is focused, is left un-stopped and bubbles
986/// up the dispatch tree to the root's own `on_key_down`
987/// (gpui-0.2.2 `window.rs`'s `dispatch_key_down_up_event`, `Bubble` phase,
988/// walks the focused node's ancestors and stops only at
989/// `cx.stop_propagation()` -- verified by reading that function, not
990/// assumed). This asserts the gate itself: only "tab" is ever intercepted,
991/// so a keybind like space (play/pause) or "s" (split) is provably never
992/// swallowed by a focused surface.
993#[test]
994fn only_tab_is_intercepted_by_a_focused_surface_everything_else_reaches_root() {
995 use crate::ui::stance::is_focus_cycle_key;
996
997 assert!(is_focus_cycle_key("tab"));
998 for key in [
999 "space", "escape", "s", "c", "left", "right", "enter", "delete", "?",
1000 ] {
1001 assert!(!is_focus_cycle_key(key), "{key} must bubble to the root");
1002 }
1003}
1004
1005/// The ring's other door, escape: [`ui::stance::is_focus_exit_key`] is the
1006/// one branch a focused surface's `on_key_down` calls to hand focus back to
1007/// the root (`Player::focus`) instead of letting escape bubble there on its
1008/// own -- same pure-function-level check as the Tab gate above, since this
1009/// crate has no window harness to drive a real `KeyDownEvent` through.
1010#[test]
1011fn escape_is_the_only_key_a_focused_surface_uses_to_leave_the_ring() {
1012 use crate::ui::stance::is_focus_exit_key;
1013
1014 assert!(is_focus_exit_key("escape"));
1015 for key in [
1016 "tab", "space", "s", "c", "left", "right", "enter", "delete", "?",
1017 ] {
1018 assert!(!is_focus_exit_key(key), "{key} must not exit the ring");
1019 }
1020}
1021
1022/// [`ActionId::FocusPanels`] is what starts the ring in the first place
1023/// (`Player::act`'s `self.focus_surface(Surface::Dock, ..)`) -- without a
1024/// bound key reaching it, `next_surface`/`is_focus_cycle_key` above are
1025/// unreachable dead code, exactly the defect this action closes.
1026#[test]
1027fn focus_panels_is_bound_and_lands_on_the_dock() {
1028 use keymap::{ActionId, Keymap};
1029
1030 let k = Keymap::defaults();
1031 assert_eq!(k.lookup("f6", false), Some(ActionId::FocusPanels));
1032 // Bare Tab must still mean Select at the root -- FocusPanels must not
1033 // have stolen it.
1034 assert_eq!(k.lookup("tab", false), Some(ActionId::Select));
1035}
1036
1037/// A card is not a key-eating black box: the room-wide chords that act on the
1038/// document -- the edit history, the project file, the clipboard -- must reach
1039/// `Player::act` while any card is open. `param_card_key` answers `true` for
1040/// *every* stroke once one of the seven is up, so the dispatch has to stand in
1041/// front of it, not only in front of the blanket modal guard under it; and the
1042/// blanket guard's own `card_open()` has to read after that dispatch too, or a
1043/// chord that got past `param_card_key` (a menu dismiss comes to mind) would
1044/// still never reach the keymap.
1045///
1046/// A scan of the handler's own source, for the reason every handler scan here
1047/// gives: this binary has no window harness to press `ctrl+z` through.
1048#[test]
1049fn an_open_card_does_not_swallow_the_document_chords() {
1050 use crate::ui::stance::card_safe_action;
1051 use keymap::ActionId;
1052 // The five the room answers through a card, and the reason each is on the
1053 // list: history, file, clipboard.
1054 for action in [
1055 ActionId::Undo,
1056 ActionId::Redo,
1057 ActionId::Save,
1058 ActionId::Copy,
1059 ActionId::Paste,
1060 ] {
1061 assert!(
1062 card_safe_action(action),
1063 "{action:?} is a document chord and a card must not eat it"
1064 );
1065 }
1066 // ...and the strokes the cards' own branch list claims stay theirs:
1067 // escape is every card's way out, `s` is the equalizer's spectrum, `x` its
1068 // band removal, `m` every card's maximize, and the digits pick a band.
1069 for action in [
1070 ActionId::Deselect,
1071 ActionId::Cut,
1072 ActionId::Delete,
1073 ActionId::ToggleMute,
1074 ActionId::Equalizer,
1075 ActionId::Color,
1076 ActionId::Loop,
1077 ActionId::TrimIn,
1078 ] {
1079 assert!(
1080 !card_safe_action(action),
1081 "{action:?} is a card's own stroke and the card must keep it"
1082 );
1083 }
1084 // The chords are real bindings, not a list of actions nothing reaches.
1085 let keys = keymap::Keymap::defaults();
1086 for (key, ctrl, action) in [
1087 ("z", true, ActionId::Undo),
1088 ("y", true, ActionId::Redo),
1089 ("s", true, ActionId::Save),
1090 ("c", true, ActionId::Copy),
1091 ("v", true, ActionId::Paste),
1092 ] {
1093 assert_eq!(
1094 keys.lookup(key, ctrl),
1095 Some(action),
1096 "the keymap no longer binds {action:?}"
1097 );
1098 }
1099 // And the dispatch stands where it has to: inside the root handler, ahead
1100 // of the cards' own branches and ahead of the blanket modal guard.
1101 let stance_rs = src_text("ui/stance.rs");
1102 let dispatch = stance_rs.find("card_safe_action(action)").expect(
1103 "the root key handler no longer asks which chords a card does not take -- an open card \
1104 eats every stroke again",
1105 );
1106 assert!(
1107 stance_rs[..dispatch].contains("this.keymap.lookup(key, ctrl)"),
1108 "the dispatch no longer goes through the keymap, so a rebind would leave it behind"
1109 );
1110 // The *statement* that dispatches, not just some `keymap.lookup` before it:
1111 // the hold gate at the top of the handler resolves the same pair, so a needle
1112 // that only asks for the lookup is satisfied by a dispatch resolving the
1113 // action some other way entirely.
1114 let resolve = stance_rs
1115 .find("if let Some(action) = this.keymap.lookup(key, ctrl)")
1116 .expect("the dispatch no longer resolves an action through the keymap");
1117 let stmt = &stance_rs[resolve..];
1118 let stmt = &stmt[..stmt.find('{').expect("the dispatch statement has no block")];
1119 assert!(
1120 stmt.contains("card_safe_action("),
1121 "the dispatch resolves an action and never asks whether a card may take \
1122 it, so an open card eats the document chords again"
1123 );
1124 for (guard, label) in [
1125 ("if this.param_card_key(", "the cards' own key branches"),
1126 ("if this.card_open()", "the blanket modal guard"),
1127 ] {
1128 let at = stance_rs
1129 .find(guard)
1130 .unwrap_or_else(|| panic!("{label} moved or was renamed"));
1131 assert!(
1132 dispatch < at,
1133 "{label} reads before the document dispatch -- an open card would \
1134 swallow undo, redo, save and the clipboard pair again"
1135 );
1136 }
1137}