Four defect classes made impossible instead of tested
Browse files at this commit5909fc91e48dce0664793f9c152e578fe58c8a6dParent: 00fea7e- fix
- four defect classes made impossible instead of tested
2 changed files +341 -94
- crates/app/src/keymap.rs +158 -82
- crates/app/src/main.rs +183 -12
crates/app/src/keymap.rsmodified+158 -82
| @@ -36,10 +36,31 @@ use std::path::{Path, PathBuf}; | |||
| 36 | /// First line, exactly. The version is part of it, as in the project file. | 36 | /// First line, exactly. The version is part of it, as in the project file. |
| 37 | const MAGIC: &str = "edith-keys 1"; | 37 | const MAGIC: &str = "edith-keys 1"; |
| 38 | 38 | ||
| 39 | -/// Everything a stroke can ask for. Not the mouse's actions: only what a key | 39 | +/// The action list, written once: the enum and the display-order array come out |
| 40 | -/// can reach is bindable. | 40 | +/// of the same names, so an action added here is in [`ActionId::ALL`] by |
| 41 | +/// construction. It used to be two lists, and a variant added to one of them | ||
| 42 | +/// compiled, passed every test, and was simply missing from the keys card -- | ||
| 43 | +/// the pointer-unreachable action this editor opened with. | ||
| 44 | +macro_rules! actions { | ||
| 45 | + ($($(#[$note:meta])* $variant:ident),+ $(,)?) => { | ||
| 46 | + /// Everything a stroke can ask for. Not the mouse's actions: only what a | ||
| 47 | + /// key can reach is bindable. | ||
| 41 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 48 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 42 | pub enum ActionId { | 49 | pub enum ActionId { |
| 50 | + $($(#[$note])* $variant,)+ | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + impl ActionId { | ||
| 54 | + /// Display order everywhere -- the editor lists them in it and | ||
| 55 | + /// [`Keymap::defaults`] binds them in it. Derived from the list | ||
| 56 | + /// above, so there is no second place to forget. | ||
| 57 | + pub const ALL: [ActionId; [$(stringify!($variant)),+].len()] = | ||
| 58 | + [$(ActionId::$variant),+]; | ||
| 59 | + } | ||
| 60 | + }; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +actions! { | ||
| 43 | Play, | 64 | Play, |
| 44 | StepBack, | 65 | StepBack, |
| 45 | StepForward, | 66 | StepForward, |
| @@ -88,53 +109,6 @@ pub enum ActionId { | |||
| 88 | } | 109 | } |
| 89 | 110 | ||
| 90 | impl ActionId { | 111 | impl ActionId { |
| 91 | - /// Display order everywhere -- the editor lists them in it and | ||
| 92 | - /// [`Keymap::defaults`] binds them in it. | ||
| 93 | - pub const ALL: [ActionId; 42] = [ | ||
| 94 | - ActionId::Play, | ||
| 95 | - ActionId::StepBack, | ||
| 96 | - ActionId::StepForward, | ||
| 97 | - ActionId::JumpBack, | ||
| 98 | - ActionId::JumpForward, | ||
| 99 | - ActionId::GoStart, | ||
| 100 | - ActionId::GoEnd, | ||
| 101 | - ActionId::Export, | ||
| 102 | - ActionId::Save, | ||
| 103 | - ActionId::Copy, | ||
| 104 | - ActionId::Paste, | ||
| 105 | - ActionId::Cut, | ||
| 106 | - ActionId::Regroup, | ||
| 107 | - ActionId::Detach, | ||
| 108 | - ActionId::Group, | ||
| 109 | - ActionId::Select, | ||
| 110 | - ActionId::SelectNext, | ||
| 111 | - ActionId::SelectPrev, | ||
| 112 | - ActionId::Delete, | ||
| 113 | - ActionId::Lift, | ||
| 114 | - ActionId::Color, | ||
| 115 | - ActionId::Fit, | ||
| 116 | - ActionId::Resolution, | ||
| 117 | - ActionId::ZoomIn, | ||
| 118 | - ActionId::ZoomOut, | ||
| 119 | - ActionId::ZoomFit, | ||
| 120 | - ActionId::Undo, | ||
| 121 | - ActionId::AddVideoLane, | ||
| 122 | - ActionId::AddAudioLane, | ||
| 123 | - ActionId::RemoveVideoLane, | ||
| 124 | - ActionId::RemoveAudioLane, | ||
| 125 | - ActionId::ToggleMute, | ||
| 126 | - ActionId::VolumeUp, | ||
| 127 | - ActionId::VolumeDown, | ||
| 128 | - ActionId::Equalizer, | ||
| 129 | - ActionId::Speed, | ||
| 130 | - ActionId::Silence, | ||
| 131 | - ActionId::Mix, | ||
| 132 | - ActionId::ToggleSnap, | ||
| 133 | - ActionId::ToggleSubtitles, | ||
| 134 | - ActionId::CancelExport, | ||
| 135 | - ActionId::ShowActions, | ||
| 136 | - ]; | ||
| 137 | - | ||
| 138 | /// What a person calls it. | 112 | /// What a person calls it. |
| 139 | pub fn label(self) -> &'static str { | 113 | pub fn label(self) -> &'static str { |
| 140 | match self { | 114 | match self { |
| @@ -347,40 +321,79 @@ impl Category { | |||
| 347 | /// and fails on any key that reaches neither this table nor a binding. | 321 | /// and fails on any key that reaches neither this table nor a binding. |
| 348 | pub struct Fixed { | 322 | pub struct Fixed { |
| 349 | /// As a person reads it, which for a single key is [`Chord::pretty`]'s | 323 | /// As a person reads it, which for a single key is [`Chord::pretty`]'s |
| 350 | - /// spelling and for a family of keys is the family (`0–9`). | 324 | + /// spelling and for a family of keys is the family (`0–9`). A `String` |
| 351 | - pub chord: &'static str, | 325 | + /// because one of them is generated: the codec row's keys are the export |
| 326 | + /// card's own table, not a line typed a second time here. | ||
| 327 | + pub chord: String, | ||
| 352 | pub label: &'static str, | 328 | pub label: &'static str, |
| 353 | pub category: Category, | 329 | pub category: Category, |
| 330 | + /// What a hand with only a mouse does instead. Every stroke here is | ||
| 331 | + /// card-local, and a card whose rows only a keyboard can reach is half this | ||
| 332 | + /// editor's users locked out of it, so each row names the thing on its card | ||
| 333 | + /// -- `every_action_is_reachable_without_the_keyboard` looks each id up in | ||
| 334 | + /// the render's own source. | ||
| 335 | + pub reach: Reach, | ||
| 336 | +} | ||
| 337 | + | ||
| 338 | +/// The pointer's answer to a fixed stroke. | ||
| 339 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 340 | +pub enum Reach { | ||
| 341 | + /// The id of the element on the card that does the same thing by click or | ||
| 342 | + /// by drag. | ||
| 343 | + Click(&'static str), | ||
| 344 | + /// Not an action a pointer takes: the way *out* of a card, and the hold | ||
| 345 | + /// that only repeats what a drag already does continuously. A variant | ||
| 346 | + /// rather than an omission, so a row with nothing to click is a decision | ||
| 347 | + /// somebody wrote down instead of a line missing from a list. | ||
| 348 | + Gesture, | ||
| 349 | +} | ||
| 350 | + | ||
| 351 | +/// The codec row's keys, from the export card's own table. Typed out here once, | ||
| 352 | +/// it named six of the seven codecs the same row's label advertised -- OGG had | ||
| 353 | +/// a key (`o`) that this card never said. | ||
| 354 | +fn codec_chord() -> String { | ||
| 355 | + crate::FORMATS | ||
| 356 | + .iter() | ||
| 357 | + .map(|(_, stroke, ..)| *stroke) | ||
| 358 | + .filter(|stroke| !stroke.is_empty()) | ||
| 359 | + .collect::<Vec<_>>() | ||
| 360 | + .join(" / ") | ||
| 354 | } | 361 | } |
| 355 | 362 | ||
| 356 | -pub const FIXED: [Fixed; 28] = [ | 363 | +pub static FIXED: std::sync::LazyLock<[Fixed; 28]> = std::sync::LazyLock::new(|| { |
| 364 | + [ | ||
| 357 | // Not a chord at all but a way of pressing one, and the only place the | 365 | // Not a chord at all but a way of pressing one, and the only place the |
| 358 | // editor can say so: holding a key that moves a *value* runs it, and | 366 | // editor can say so: holding a key that moves a *value* runs it, and |
| 359 | // holding anything else still does what one press did. | 367 | // holding anything else still does what one press did. |
| 360 | Fixed { | 368 | Fixed { |
| 361 | - chord: "hold ← → ↑ ↓", | 369 | + chord: "hold ← → ↑ ↓".into(), |
| 362 | label: "Run a card's slider, or the volume and zoom keys, while held", | 370 | label: "Run a card's slider, or the volume and zoom keys, while held", |
| 363 | category: Category::View, | 371 | category: Category::View, |
| 372 | + reach: Reach::Gesture, | ||
| 364 | }, | 373 | }, |
| 365 | Fixed { | 374 | Fixed { |
| 366 | - chord: "esc", | 375 | + chord: "esc".into(), |
| 367 | label: "Close this card or menu, or cancel a capture", | 376 | label: "Close this card or menu, or cancel a capture", |
| 368 | category: Category::View, | 377 | category: Category::View, |
| 378 | + reach: Reach::Gesture, | ||
| 369 | }, | 379 | }, |
| 370 | Fixed { | 380 | Fixed { |
| 371 | - chord: "n", | 381 | + chord: "n".into(), |
| 372 | label: "Open the custom export bitrate field — ↑↓ step it", | 382 | label: "Open the custom export bitrate field — ↑↓ step it", |
| 373 | category: Category::File, | 383 | category: Category::File, |
| 384 | + reach: Reach::Click("quality"), | ||
| 374 | }, | 385 | }, |
| 375 | Fixed { | 386 | Fixed { |
| 376 | - chord: "0–9", | 387 | + chord: "0–9".into(), |
| 377 | label: "Type into that field — nothing outside it", | 388 | label: "Type into that field — nothing outside it", |
| 378 | category: Category::File, | 389 | category: Category::File, |
| 390 | + reach: Reach::Click("mbps-up"), | ||
| 379 | }, | 391 | }, |
| 380 | Fixed { | 392 | Fixed { |
| 381 | - chord: "m / a / h / w / f / p", | 393 | + chord: codec_chord(), |
| 382 | label: "Pick the export codec: H.264, AV1, HEVC, WAV, FLAC, MP3 or OGG", | 394 | label: "Pick the export codec: H.264, AV1, HEVC, WAV, FLAC, MP3 or OGG", |
| 383 | category: Category::File, | 395 | category: Category::File, |
| 396 | + reach: Reach::Click("format"), | ||
| 384 | }, | 397 | }, |
| 385 | // The rest of the export card's own rows, each on the letter its row is | 398 | // The rest of the export card's own rows, each on the letter its row is |
| 386 | // named after. They shadow the clip keys of the same letter while the card | 399 | // named after. They shadow the clip keys of the same letter while the card |
| @@ -388,130 +401,154 @@ pub const FIXED: [Fixed; 28] = [ | |||
| 388 | // card owns the keyboard, and cutting a clip under it is not a thing that | 401 | // card owns the keyboard, and cutting a clip under it is not a thing that |
| 389 | // can happen anyway. | 402 | // can happen anyway. |
| 390 | Fixed { | 403 | Fixed { |
| 391 | - chord: "c", | 404 | + chord: "c".into(), |
| 392 | label: "Switch the export container: Matroska or MP4", | 405 | label: "Switch the export container: Matroska or MP4", |
| 393 | category: Category::File, | 406 | category: Category::File, |
| 407 | + reach: Reach::Click("container"), | ||
| 394 | }, | 408 | }, |
| 395 | Fixed { | 409 | Fixed { |
| 396 | - chord: "q", | 410 | + chord: "q".into(), |
| 397 | label: "Step through the export quality rows", | 411 | label: "Step through the export quality rows", |
| 398 | category: Category::File, | 412 | category: Category::File, |
| 413 | + reach: Reach::Click("quality"), | ||
| 399 | }, | 414 | }, |
| 400 | Fixed { | 415 | Fixed { |
| 401 | - chord: "b", | 416 | + chord: "b".into(), |
| 402 | label: "Step through the export sound bitrates", | 417 | label: "Step through the export sound bitrates", |
| 403 | category: Category::File, | 418 | category: Category::File, |
| 419 | + reach: Reach::Click("sound"), | ||
| 404 | }, | 420 | }, |
| 405 | Fixed { | 421 | Fixed { |
| 406 | - chord: "d", | 422 | + chord: "d".into(), |
| 407 | label: "Choose where the export is written", | 423 | label: "Choose where the export is written", |
| 408 | category: Category::File, | 424 | category: Category::File, |
| 425 | + reach: Reach::Click("destination"), | ||
| 409 | }, | 426 | }, |
| 410 | Fixed { | 427 | Fixed { |
| 411 | - chord: "g", | 428 | + chord: "g".into(), |
| 412 | label: "Export card: sections or one flat list", | 429 | label: "Export card: sections or one flat list", |
| 413 | category: Category::File, | 430 | category: Category::File, |
| 431 | + reach: Reach::Click("export-layout"), | ||
| 414 | }, | 432 | }, |
| 415 | Fixed { | 433 | Fixed { |
| 416 | - chord: "r", | 434 | + chord: "r".into(), |
| 417 | label: "Export card: the formats with no encoder as rows or as one line", | 435 | label: "Export card: the formats with no encoder as rows or as one line", |
| 418 | category: Category::File, | 436 | category: Category::File, |
| 437 | + reach: Reach::Click("export-refusals"), | ||
| 419 | }, | 438 | }, |
| 420 | Fixed { | 439 | Fixed { |
| 421 | - chord: "enter", | 440 | + chord: "enter".into(), |
| 422 | label: "Start the export — or commit the bitrate field", | 441 | label: "Start the export — or commit the bitrate field", |
| 423 | category: Category::File, | 442 | category: Category::File, |
| 443 | + reach: Reach::Click("export-confirm"), | ||
| 424 | }, | 444 | }, |
| 425 | Fixed { | 445 | Fixed { |
| 426 | - chord: "backspace", | 446 | + chord: "backspace".into(), |
| 427 | label: "Erase a digit in the bitrate field", | 447 | label: "Erase a digit in the bitrate field", |
| 428 | category: Category::File, | 448 | category: Category::File, |
| 449 | + reach: Reach::Click("mbps-down"), | ||
| 429 | }, | 450 | }, |
| 430 | // The equalizer card's own input, for the same reason the export card has | 451 | // The equalizer card's own input, for the same reason the export card has |
| 431 | // its own: a band nothing but a drag can reach is a band half the users of | 452 | // its own: a band nothing but a drag can reach is a band half the users of |
| 432 | // this editor cannot move at all. Card-local, so none of them is bindable. | 453 | // this editor cannot move at all. Card-local, so none of them is bindable. |
| 433 | Fixed { | 454 | Fixed { |
| 434 | - chord: "1–9, 0", | 455 | + chord: "1–9, 0".into(), |
| 435 | label: "Pick an equalizer band", | 456 | label: "Pick an equalizer band", |
| 436 | category: Category::Audio, | 457 | category: Category::Audio, |
| 458 | + reach: Reach::Click("eq-graph"), | ||
| 437 | }, | 459 | }, |
| 438 | Fixed { | 460 | Fixed { |
| 439 | - chord: "up", | 461 | + chord: "up".into(), |
| 440 | label: "Raise the picked band 1 dB", | 462 | label: "Raise the picked band 1 dB", |
| 441 | category: Category::Audio, | 463 | category: Category::Audio, |
| 464 | + reach: Reach::Click("eq-gain-up"), | ||
| 442 | }, | 465 | }, |
| 443 | Fixed { | 466 | Fixed { |
| 444 | - chord: "down", | 467 | + chord: "down".into(), |
| 445 | label: "Lower the picked band 1 dB", | 468 | label: "Lower the picked band 1 dB", |
| 446 | category: Category::Audio, | 469 | category: Category::Audio, |
| 470 | + reach: Reach::Click("eq-gain-down"), | ||
| 447 | }, | 471 | }, |
| 448 | Fixed { | 472 | Fixed { |
| 449 | - chord: "← / →", | 473 | + chord: "← / →".into(), |
| 450 | label: "Move the picked band down or up in frequency", | 474 | label: "Move the picked band down or up in frequency", |
| 451 | category: Category::Audio, | 475 | category: Category::Audio, |
| 476 | + reach: Reach::Click("eq-freq-up"), | ||
| 452 | }, | 477 | }, |
| 453 | Fixed { | 478 | Fixed { |
| 454 | - chord: "shift ← / →", | 479 | + chord: "shift ← / →".into(), |
| 455 | label: "Widen or narrow the picked band (its Q)", | 480 | label: "Widen or narrow the picked band (its Q)", |
| 456 | category: Category::Audio, | 481 | category: Category::Audio, |
| 482 | + reach: Reach::Click("eq-q-wider"), | ||
| 457 | }, | 483 | }, |
| 458 | Fixed { | 484 | Fixed { |
| 459 | - chord: "a", | 485 | + chord: "a".into(), |
| 460 | label: "Add an equalizer band beside the picked one", | 486 | label: "Add an equalizer band beside the picked one", |
| 461 | category: Category::Audio, | 487 | category: Category::Audio, |
| 488 | + reach: Reach::Click("eq-add"), | ||
| 462 | }, | 489 | }, |
| 463 | Fixed { | 490 | Fixed { |
| 464 | - chord: "x", | 491 | + chord: "x".into(), |
| 465 | label: "Remove the picked equalizer band", | 492 | label: "Remove the picked equalizer band", |
| 466 | category: Category::Audio, | 493 | category: Category::Audio, |
| 494 | + reach: Reach::Click("eq-remove"), | ||
| 467 | }, | 495 | }, |
| 468 | Fixed { | 496 | Fixed { |
| 469 | - chord: "f", | 497 | + chord: "f".into(), |
| 470 | label: "Flatten the picked band (double-click does the same)", | 498 | label: "Flatten the picked band (double-click does the same)", |
| 471 | category: Category::Audio, | 499 | category: Category::Audio, |
| 500 | + reach: Reach::Click("eq-flat-band"), | ||
| 472 | }, | 501 | }, |
| 473 | Fixed { | 502 | Fixed { |
| 474 | - chord: "r", | 503 | + chord: "r".into(), |
| 475 | label: "Flatten every band", | 504 | label: "Flatten every band", |
| 476 | category: Category::Audio, | 505 | category: Category::Audio, |
| 506 | + reach: Reach::Click("eq-reset"), | ||
| 477 | }, | 507 | }, |
| 478 | Fixed { | 508 | Fixed { |
| 479 | - chord: "s", | 509 | + chord: "s".into(), |
| 480 | label: "Show or hide the spectrum behind the curve", | 510 | label: "Show or hide the spectrum behind the curve", |
| 481 | category: Category::Audio, | 511 | category: Category::Audio, |
| 512 | + reach: Reach::Click("eq-spectrum"), | ||
| 482 | }, | 513 | }, |
| 483 | // The colour card's own three, which mean nothing outside it -- the same | 514 | // The colour card's own three, which mean nothing outside it -- the same |
| 484 | // card-local input the export card's digits are. | 515 | // card-local input the export card's digits are. |
| 485 | Fixed { | 516 | Fixed { |
| 486 | - chord: "↑ / ↓", | 517 | + chord: "↑ / ↓".into(), |
| 487 | label: "Pick a colour slider", | 518 | label: "Pick a colour slider", |
| 488 | category: Category::Clips, | 519 | category: Category::Clips, |
| 520 | + reach: Reach::Click("color-row"), | ||
| 489 | }, | 521 | }, |
| 490 | Fixed { | 522 | Fixed { |
| 491 | - chord: "← / →", | 523 | + chord: "← / →".into(), |
| 492 | label: "Move the picked colour slider", | 524 | label: "Move the picked colour slider", |
| 493 | category: Category::Clips, | 525 | category: Category::Clips, |
| 526 | + reach: Reach::Click("color-bar"), | ||
| 494 | }, | 527 | }, |
| 495 | Fixed { | 528 | Fixed { |
| 496 | - chord: "r", | 529 | + chord: "r".into(), |
| 497 | label: "Take the colour grade off the clip", | 530 | label: "Take the colour grade off the clip", |
| 498 | category: Category::Clips, | 531 | category: Category::Clips, |
| 532 | + reach: Reach::Click("color-reset"), | ||
| 499 | }, | 533 | }, |
| 500 | // The silence card's two apply keys. Card-local like every stroke above -- | 534 | // The silence card's two apply keys. Card-local like every stroke above -- |
| 501 | // they mean nothing while it is closed -- but the card is the one place in | 535 | // they mean nothing while it is closed -- but the card is the one place in |
| 502 | // this editor where a key rewrites forty places at once, so both of them | 536 | // this editor where a key rewrites forty places at once, so both of them |
| 503 | // are listed rather than hidden in the card's own hint line. | 537 | // are listed rather than hidden in the card's own hint line. |
| 504 | Fixed { | 538 | Fixed { |
| 505 | - chord: "enter", | 539 | + chord: "enter".into(), |
| 506 | label: "Cut every silence the card found", | 540 | label: "Cut every silence the card found", |
| 507 | category: Category::Clips, | 541 | category: Category::Clips, |
| 542 | + reach: Reach::Click("silence-apply"), | ||
| 508 | }, | 543 | }, |
| 509 | Fixed { | 544 | Fixed { |
| 510 | - chord: "f", | 545 | + chord: "f".into(), |
| 511 | label: "Speed the silences up instead of cutting them", | 546 | label: "Speed the silences up instead of cutting them", |
| 512 | category: Category::Clips, | 547 | category: Category::Clips, |
| 548 | + reach: Reach::Click("silence-apply"), | ||
| 513 | }, | 549 | }, |
| 514 | -]; | 550 | + ] |
| 551 | +}); | ||
| 515 | 552 | ||
| 516 | /// A stroke as the key handler sees it: gpui's key name plus the one modifier | 553 | /// A stroke as the key handler sees it: gpui's key name plus the one modifier |
| 517 | /// this editor binds. Nothing else is a chord here -- shift and alt are part of | 554 | /// this editor binds. Nothing else is a chord here -- shift and alt are part of |
| @@ -1222,13 +1259,52 @@ mod tests { | |||
| 1222 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); | 1259 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 1223 | // The label is the editor's column, and never the file's word for it. | 1260 | // The label is the editor's column, and never the file's word for it. |
| 1224 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); | 1261 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 1225 | - assert_eq!(ActionId::ALL.len(), 42); | ||
| 1226 | assert_eq!(k.display(ActionId::ToggleSnap), "n"); | 1262 | assert_eq!(k.display(ActionId::ToggleSnap), "n"); |
| 1227 | assert_eq!(k.display(ActionId::ShowActions), "f1"); | 1263 | assert_eq!(k.display(ActionId::ShowActions), "f1"); |
| 1228 | assert_eq!(k.display(ActionId::ToggleSubtitles), "t"); | 1264 | assert_eq!(k.display(ActionId::ToggleSubtitles), "t"); |
| 1229 | assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); | 1265 | assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); |
| 1230 | } | 1266 | } |
| 1231 | 1267 | ||
| 1268 | + /// The one row of [`FIXED`] that speaks for a whole table elsewhere: it | ||
| 1269 | + /// named six keys for seven codecs, and OGG's `o` was a stroke the card | ||
| 1270 | + /// never mentioned. The chord is generated from `FORMATS` now, and this | ||
| 1271 | + /// holds the *label* to the same table -- a codec added there with no name | ||
| 1272 | + /// in this row fails here rather than in a user's hands. | ||
| 1273 | + #[test] | ||
| 1274 | + fn the_codec_row_says_every_codec_the_export_card_offers() { | ||
| 1275 | + let row = super::FIXED | ||
| 1276 | + .iter() | ||
| 1277 | + .find(|f| f.label.starts_with("Pick the export codec")) | ||
| 1278 | + .expect("the codec row"); | ||
| 1279 | + let keys: Vec<&str> = row.chord.split(" / ").collect(); | ||
| 1280 | + for (boxes, stroke, label, _) in crate::FORMATS { | ||
| 1281 | + if stroke.is_empty() { | ||
| 1282 | + // A codec this program cannot write at all has no key and no | ||
| 1283 | + // business in this row. | ||
| 1284 | + assert!(boxes.is_empty(), "{label} has a box but no stroke"); | ||
| 1285 | + assert!(!keys.contains(&stroke)); | ||
| 1286 | + continue; | ||
| 1287 | + } | ||
| 1288 | + assert!( | ||
| 1289 | + keys.contains(&stroke), | ||
| 1290 | + "{label}'s key {stroke:?} is not in {:?}", | ||
| 1291 | + row.chord | ||
| 1292 | + ); | ||
| 1293 | + assert!( | ||
| 1294 | + row.label.contains(label), | ||
| 1295 | + "{label} is not named in {:?}", | ||
| 1296 | + row.label | ||
| 1297 | + ); | ||
| 1298 | + } | ||
| 1299 | + assert_eq!( | ||
| 1300 | + keys.len(), | ||
| 1301 | + crate::FORMATS | ||
| 1302 | + .iter() | ||
| 1303 | + .filter(|(_, s, ..)| !s.is_empty()) | ||
| 1304 | + .count() | ||
| 1305 | + ); | ||
| 1306 | + } | ||
| 1307 | + | ||
| 1232 | #[test] | 1308 | #[test] |
| 1233 | fn a_saved_keymap_comes_back_off_the_disk() { | 1309 | fn a_saved_keymap_comes_back_off_the_disk() { |
| 1234 | // Its own directory, never the real config one: this test writes. | 1310 | // Its own directory, never the real config one: this test writes. |
crates/app/src/main.rsmodified+183 -12
| @@ -473,6 +473,18 @@ struct Trim { | |||
| 473 | /// still the body. | 473 | /// still the body. |
| 474 | const EDGE_W: f32 = 6.; | 474 | const EDGE_W: f32 = 6.; |
| 475 | 475 | ||
| 476 | +/// Whether a clip box this wide gets its two trim strips at all. Below three | ||
| 477 | +/// handles wide the pair would occlude the whole box: every press on it would | ||
| 478 | +/// trim, and the clip could not be selected, dragged to another lane or picked | ||
| 479 | +/// up by its middle -- which is exactly what a jumpcut leaves behind | ||
| 480 | +/// ([`Player::cut_silences`] manufactures a great many short clips). Above it, | ||
| 481 | +/// what is left between the two strips is a handle's width of body in its own | ||
| 482 | +/// right. A clip too short for its handles is trimmed by zooming in first: the | ||
| 483 | +/// bed is a magnifier, and the strip grows with the box. | ||
| 484 | +fn trims(width: f32) -> bool { | ||
| 485 | + width >= 3. * EDGE_W | ||
| 486 | +} | ||
| 487 | + | ||
| 476 | /// How close to an edge a dragged clip has to be let go for it to land *on* it: | 488 | /// How close to an edge a dragged clip has to be let go for it to land *on* it: |
| 477 | /// the snap every timeline has, in pixels rather than frames so that it feels | 489 | /// the snap every timeline has, in pixels rather than frames so that it feels |
| 478 | /// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two | 490 | /// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two |
| @@ -693,7 +705,7 @@ fn keys_filter(needle: &str, keymap: &Keymap) -> Vec<(usize, KeyRow)> { | |||
| 693 | } | 705 | } |
| 694 | KeyRow::Fixed(f) => { | 706 | KeyRow::Fixed(f) => { |
| 695 | let fixed = &keymap::FIXED[*f]; | 707 | let fixed = &keymap::FIXED[*f]; |
| 696 | - if hit(fixed.label, fixed.chord) { | 708 | + if hit(fixed.label, &fixed.chord) { |
| 697 | out.extend(pending.take()); | 709 | out.extend(pending.take()); |
| 698 | out.push((i, row)); | 710 | out.push((i, row)); |
| 699 | } | 711 | } |
| @@ -6196,13 +6208,26 @@ impl Player { | |||
| 6196 | // off the right edge is a button a pointer cannot press. A plain | 6208 | // off the right edge is a button a pointer cannot press. A plain |
| 6197 | // wheel moves it -- gpui puts a vertical delta on the x axis when | 6209 | // wheel moves it -- gpui puts a vertical delta on the x axis when |
| 6198 | // that is the only one scrolling (div.rs:2424). | 6210 | // that is the only one scrolling (div.rs:2424). |
| 6211 | + // | ||
| 6212 | + // ...and "it scrolls" is not "it can be found": the button beside | ||
| 6213 | + // the row is pinned outside it and never scrolls away, so Export, | ||
| 6214 | + // Save and the rest are one press from the smallest window even | ||
| 6215 | + // when the row's tail is off the edge. | ||
| 6216 | + // `toolbar_fits_the_smallest_window` is the guard. | ||
| 6199 | .child( | 6217 | .child( |
| 6200 | div() | 6218 | div() |
| 6201 | - .id("controls") | ||
| 6202 | .flex_none() | 6219 | .flex_none() |
| 6203 | .flex() | 6220 | .flex() |
| 6204 | .items_center() | 6221 | .items_center() |
| 6205 | .gap(px(8.)) | 6222 | .gap(px(8.)) |
| 6223 | + .child( | ||
| 6224 | + div() | ||
| 6225 | + .id("controls") | ||
| 6226 | + .flex_1() | ||
| 6227 | + .min_w(px(0.)) | ||
| 6228 | + .flex() | ||
| 6229 | + .items_center() | ||
| 6230 | + .gap(px(8.)) | ||
| 6206 | .overflow_x_scroll() | 6231 | .overflow_x_scroll() |
| 6207 | .child(control( | 6232 | .child(control( |
| 6208 | "transport", | 6233 | "transport", |
| @@ -6548,6 +6573,28 @@ impl Player { | |||
| 6548 | } | 6573 | } |
| 6549 | false => this.show_actions(cx), | 6574 | false => this.show_actions(cx), |
| 6550 | }), | 6575 | }), |
| 6576 | + )) | ||
| 6577 | + ) | ||
| 6578 | + // The door to everything the row cannot show at this | ||
| 6579 | + // window: the same card the Actions button opens, by the | ||
| 6580 | + // same call, pinned where a scroll cannot take it. | ||
| 6581 | + .child(control( | ||
| 6582 | + "controls-more", | ||
| 6583 | + None, | ||
| 6584 | + "⋯", | ||
| 6585 | + format!( | ||
| 6586 | + "{} — every action, including the ones scrolled off this row", | ||
| 6587 | + key(ActionId::ShowActions) | ||
| 6588 | + ), | ||
| 6589 | + !exporting, | ||
| 6590 | + cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | ||
| 6591 | + true => { | ||
| 6592 | + this.keys_open = false; | ||
| 6593 | + this.rebinding = None; | ||
| 6594 | + cx.notify(); | ||
| 6595 | + } | ||
| 6596 | + false => this.show_actions(cx), | ||
| 6597 | + }), | ||
| 6551 | )), | 6598 | )), |
| 6552 | ) | 6599 | ) |
| 6553 | .child( | 6600 | .child( |
| @@ -6962,7 +7009,7 @@ impl Player { | |||
| 6962 | row() | 7009 | row() |
| 6963 | .child(f.label) | 7010 | .child(f.label) |
| 6964 | // Dim, and no hover: this one is not a row you can click. | 7011 | // Dim, and no hover: this one is not a row you can click. |
| 6965 | - .child(div().text_color(rgb(INK_DIM)).child(f.chord)) | 7012 | + .child(div().text_color(rgb(INK_DIM)).child(f.chord.clone())) |
| 6966 | .into_any_element() | 7013 | .into_any_element() |
| 6967 | } | 7014 | } |
| 6968 | }); | 7015 | }); |
| @@ -7343,6 +7390,45 @@ impl Player { | |||
| 7343 | ) | 7390 | ) |
| 7344 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) | 7391 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) |
| 7345 | .into_any_element(); | 7392 | .into_any_element(); |
| 7393 | + // The card's own two layout switches. They were `g` and `r` and nothing | ||
| 7394 | + // else, while the status line under the title advertised both of them: | ||
| 7395 | + // a hand on the mouse read what they do and had nothing to press. | ||
| 7396 | + list.push( | ||
| 7397 | + entry( | ||
| 7398 | + ("export-layout", 0), | ||
| 7399 | + "g", | ||
| 7400 | + "Layout".into(), | ||
| 7401 | + match self.export_grouped { | ||
| 7402 | + true => "sections — g for one flat list".into(), | ||
| 7403 | + false => "one flat list — g for sections".into(), | ||
| 7404 | + }, | ||
| 7405 | + self.export_grouped, | ||
| 7406 | + true, | ||
| 7407 | + ) | ||
| 7408 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 7409 | + this.export_grouped = !this.export_grouped; | ||
| 7410 | + cx.notify(); | ||
| 7411 | + })) | ||
| 7412 | + .into_any_element(), | ||
| 7413 | + ); | ||
| 7414 | + list.push( | ||
| 7415 | + entry( | ||
| 7416 | + ("export-refusals", 0), | ||
| 7417 | + "r", | ||
| 7418 | + "Codecs with no encoder".into(), | ||
| 7419 | + match self.export_refusals_inline { | ||
| 7420 | + true => "a dimmed row each — r collapses them".into(), | ||
| 7421 | + false => "one line at the foot — r shows a row each".into(), | ||
| 7422 | + }, | ||
| 7423 | + self.export_refusals_inline, | ||
| 7424 | + true, | ||
| 7425 | + ) | ||
| 7426 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 7427 | + this.export_refusals_inline = !this.export_refusals_inline; | ||
| 7428 | + cx.notify(); | ||
| 7429 | + })) | ||
| 7430 | + .into_any_element(), | ||
| 7431 | + ); | ||
| 7346 | match self.export_grouped { | 7432 | match self.export_grouped { |
| 7347 | true => list.push(destination), | 7433 | true => list.push(destination), |
| 7348 | // Flat: the same rows with no headers over them, and the | 7434 | // Flat: the same rows with no headers over them, and the |
| @@ -9634,7 +9720,11 @@ impl Player { | |||
| 9634 | // them, which is what keeps one gesture one thing: | 9720 | // them, which is what keeps one gesture one thing: |
| 9635 | // a press here trims, a press anywhere else on the | 9721 | // a press here trims, a press anywhere else on the |
| 9636 | // box still starts the move to another lane. | 9722 | // box still starts the move to another lane. |
| 9637 | - .children([Edge::Start, Edge::End].map(|edge| { | 9723 | + .children( |
| 9724 | + [Edge::Start, Edge::End] | ||
| 9725 | + .into_iter() | ||
| 9726 | + .filter(|_| trims(width)) | ||
| 9727 | + .map(|edge| { | ||
| 9638 | let mut zone = div() | 9728 | let mut zone = div() |
| 9639 | .absolute() | 9729 | .absolute() |
| 9640 | .top_0() | 9730 | .top_0() |
| @@ -9645,25 +9735,30 @@ impl Player { | |||
| 9645 | .hover(|s| s.bg(rgb(ACCENT))) | 9735 | .hover(|s| s.bg(rgb(ACCENT))) |
| 9646 | .on_mouse_down( | 9736 | .on_mouse_down( |
| 9647 | MouseButton::Left, | 9737 | MouseButton::Left, |
| 9648 | - cx.listener(move |this, _: &MouseDownEvent, _, cx| { | 9738 | + cx.listener( |
| 9739 | + move |this, _: &MouseDownEvent, _, cx| { | ||
| 9649 | this.start_trim(lane, i, edge, cx); | 9740 | this.start_trim(lane, i, edge, cx); |
| 9650 | - }), | 9741 | + }, |
| 9742 | + ), | ||
| 9651 | ) | 9743 | ) |
| 9652 | // Occluded, so the box's own right-button | 9744 | // Occluded, so the box's own right-button |
| 9653 | // listener never fires here: the menu is | 9745 | // listener never fires here: the menu is |
| 9654 | // the same menu, opened by the same call. | 9746 | // the same menu, opened by the same call. |
| 9655 | .on_mouse_down( | 9747 | .on_mouse_down( |
| 9656 | MouseButton::Right, | 9748 | MouseButton::Right, |
| 9657 | - cx.listener(move |this, event: &MouseDownEvent, _, cx| { | 9749 | + cx.listener( |
| 9750 | + move |this, event: &MouseDownEvent, _, cx| { | ||
| 9658 | this.open_menu(lane, i, event.position, cx); | 9751 | this.open_menu(lane, i, event.position, cx); |
| 9659 | - }), | 9752 | + }, |
| 9753 | + ), | ||
| 9660 | ); | 9754 | ); |
| 9661 | zone = match edge { | 9755 | zone = match edge { |
| 9662 | Edge::Start => zone.left_0(), | 9756 | Edge::Start => zone.left_0(), |
| 9663 | Edge::End => zone.right_0(), | 9757 | Edge::End => zone.right_0(), |
| 9664 | }; | 9758 | }; |
| 9665 | zone | 9759 | zone |
| 9666 | - })) | 9760 | + }), |
| 9761 | + ) | ||
| 9667 | // Under the label row, never through it. | 9762 | // Under the label row, never through it. |
| 9668 | .children(wave.filter(|_| audio && vis_w > 0.).and_then(|wave| { | 9763 | .children(wave.filter(|_| audio && vis_w > 0.).and_then(|wave| { |
| 9669 | let inner: AnyElement = match wave { | 9764 | let inner: AnyElement = match wave { |
| @@ -13179,7 +13274,7 @@ mod tests { | |||
| 13179 | whole_take, window_title, | 13274 | whole_take, window_title, |
| 13180 | }; | 13275 | }; |
| 13181 | use super::{ | 13276 | use super::{ |
| 13182 | - Choice, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, | 13277 | + Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, |
| 13183 | Scale, View, | 13278 | Scale, View, |
| 13184 | ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, | 13279 | ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, |
| 13185 | fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, | 13280 | fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, |
| @@ -13188,7 +13283,7 @@ mod tests { | |||
| 13188 | Landing, arrival, launch_queue, | 13283 | Landing, arrival, launch_queue, |
| 13189 | read_ahead, scan_plan, seek_line, silence_line, stash_or_write, | 13284 | read_ahead, scan_plan, seek_line, silence_line, stash_or_write, |
| 13190 | repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, | 13285 | repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, |
| 13191 | - trimmed_clip, unscannable, | 13286 | + trimmed_clip, trims, unscannable, |
| 13192 | visible_slice, | 13287 | visible_slice, |
| 13193 | }; | 13288 | }; |
| 13194 | use super::{ | 13289 | use super::{ |
| @@ -13806,6 +13901,25 @@ mod tests { | |||
| 13806 | ] { | 13901 | ] { |
| 13807 | assert!(element(id), "{id} is not on any card"); | 13902 | assert!(element(id), "{id} is not on any card"); |
| 13808 | } | 13903 | } |
| 13904 | + // ...and each one is named by the row that carries its stroke, so a | ||
| 13905 | + // card-local key added to `FIXED` with nothing to click fails here | ||
| 13906 | + // instead of being noticed by whoever tries to use the card without a | ||
| 13907 | + // keyboard. `KeyRow::Fixed` is "shown and never offered", which used to | ||
| 13908 | + // mean the twenty-eight rows below were the one part of this editor no | ||
| 13909 | + // reachability test read. | ||
| 13910 | + for fixed in keymap::FIXED.iter() { | ||
| 13911 | + match fixed.reach { | ||
| 13912 | + keymap::Reach::Click(id) => assert!( | ||
| 13913 | + element(id), | ||
| 13914 | + "{:?} ({}) points at {id}, which is on no card", | ||
| 13915 | + fixed.chord, | ||
| 13916 | + fixed.label | ||
| 13917 | + ), | ||
| 13918 | + // Nothing to click by decision, not by omission: getting out of | ||
| 13919 | + // a card, and the hold that repeats what a drag already does. | ||
| 13920 | + keymap::Reach::Gesture => {} | ||
| 13921 | + } | ||
| 13922 | + } | ||
| 13809 | } | 13923 | } |
| 13810 | 13924 | ||
| 13811 | /// What the Detach and Group items do to a real timeline: a music video's | 13925 | /// What the Detach and Group items do to a real timeline: a music video's |
| @@ -14772,7 +14886,7 @@ mod tests { | |||
| 14772 | for action in ActionId::ALL { | 14886 | for action in ActionId::ALL { |
| 14773 | assert!(keymap::Category::ALL.contains(&action.category())); | 14887 | assert!(keymap::Category::ALL.contains(&action.category())); |
| 14774 | } | 14888 | } |
| 14775 | - for fixed in &keymap::FIXED { | 14889 | + for fixed in keymap::FIXED.iter() { |
| 14776 | assert!(keymap::Category::ALL.contains(&fixed.category)); | 14890 | assert!(keymap::Category::ALL.contains(&fixed.category)); |
| 14777 | } | 14891 | } |
| 14778 | } | 14892 | } |
| @@ -17303,6 +17417,45 @@ mod tests { | |||
| 17303 | assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); | 17417 | assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); |
| 17304 | } | 17418 | } |
| 17305 | 17419 | ||
| 17420 | + /// The panel's button row against the 640x360 floor the whole editor is | ||
| 17421 | + /// measured at. It does not fit and cannot be made to -- so what it may | ||
| 17422 | + /// never do is *hide* the tail: the row scrolls, and the door to everything | ||
| 17423 | + /// scrolled off it is pinned outside the scrolling box. | ||
| 17424 | + #[test] | ||
| 17425 | + fn toolbar_fits_the_smallest_window() { | ||
| 17426 | + let source = include_str!("main.rs") | ||
| 17427 | + .split("#[cfg(test)]") | ||
| 17428 | + .next() | ||
| 17429 | + .unwrap(); | ||
| 17430 | + let panel = &source[source.find(" fn panel(").expect("the panel") | ||
| 17431 | + ..source.find(" fn import_bar(").expect("the panel's end")]; | ||
| 17432 | + // Every button in the row is a hit target, so none of them is narrower | ||
| 17433 | + // than `HIT_MIN`, and they sit in 8 px gaps inside the panel's own | ||
| 17434 | + // 12 px padding. The level slider is the one fixed width among them. | ||
| 17435 | + let buttons = panel.matches("control(").count(); | ||
| 17436 | + assert!(buttons >= 15, "the row's buttons moved; this scan is blind"); | ||
| 17437 | + let row_w = buttons as f32 * (HIT_MIN + 8.) + VOLUME_W + 24.; | ||
| 17438 | + assert!( | ||
| 17439 | + row_w > 640., | ||
| 17440 | + "{row_w} px of buttons now fits the floor -- the pinned door may go" | ||
| 17441 | + ); | ||
| 17442 | + // So Export, Save and Actions are off the right edge at that width, and | ||
| 17443 | + // "it scrolls" is not "it can be found": this is the button that never | ||
| 17444 | + // scrolls, and the card it opens carries every action there is | ||
| 17445 | + // (`every_action_is_on_the_actions_card`). | ||
| 17446 | + assert!( | ||
| 17447 | + panel.contains("\"controls-more\""), | ||
| 17448 | + "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" | ||
| 17449 | + ); | ||
| 17450 | + // ...and it is outside the scrolling box, which is the whole point of | ||
| 17451 | + // it: one `overflow_x_scroll`, and the door is written after it closes. | ||
| 17452 | + assert_eq!(panel.matches("overflow_x_scroll").count(), 1); | ||
| 17453 | + assert!( | ||
| 17454 | + panel.find("\"controls-more\"") > panel.find("overflow_x_scroll"), | ||
| 17455 | + "the pinned door is inside the row it is meant to outlive" | ||
| 17456 | + ); | ||
| 17457 | + } | ||
| 17458 | + | ||
| 17306 | #[test] | 17459 | #[test] |
| 17307 | fn nothing_clickable_is_smaller_than_the_wcag_minimum() { | 17460 | fn nothing_clickable_is_smaller_than_the_wcag_minimum() { |
| 17308 | // Every hit target in the panel, including the scrub strip -- whose bar | 17461 | // Every hit target in the panel, including the scrub strip -- whose bar |
| @@ -17310,6 +17463,24 @@ mod tests { | |||
| 17310 | assert!(CONTROL_H >= HIT_MIN); | 17463 | assert!(CONTROL_H >= HIT_MIN); |
| 17311 | assert!(RULER_HIT_H >= HIT_MIN); | 17464 | assert!(RULER_HIT_H >= HIT_MIN); |
| 17312 | assert!(LANE_H >= HIT_MIN); | 17465 | assert!(LANE_H >= HIT_MIN); |
| 17466 | + // A clip box is a hit target too, and its two trim strips occlude it: | ||
| 17467 | + // on a box narrower than the pair there is no body left to press, so | ||
| 17468 | + // the clip cannot be selected, dragged or menued at all -- which is | ||
| 17469 | + // every clip a jumpcut leaves at a normal zoom. Below three handles | ||
| 17470 | + // there are no strips. | ||
| 17471 | + assert!(!trims(0.)); | ||
| 17472 | + assert!(!trims(EDGE_W)); | ||
| 17473 | + assert!(!trims(2. * EDGE_W), "a box that is all handle and no clip"); | ||
| 17474 | + assert!(!trims(3. * EDGE_W - 0.1)); | ||
| 17475 | + // And where they are drawn, what is left between them is a hit target | ||
| 17476 | + // in its own right -- a whole handle's width of clip. | ||
| 17477 | + for width in [3. * EDGE_W, 24., 100., 4000.] { | ||
| 17478 | + assert!(trims(width)); | ||
| 17479 | + assert!( | ||
| 17480 | + width - 2. * EDGE_W >= EDGE_W, | ||
| 17481 | + "{width} px of box leaves no middle" | ||
| 17482 | + ); | ||
| 17483 | + } | ||
| 17313 | } | 17484 | } |
| 17314 | 17485 | ||
| 17315 | /// WCAG 2.1 relative luminance of a packed `0xRRGGBB`. | 17486 | /// WCAG 2.1 relative luminance of a packed `0xRRGGBB`. |