Merge branch 'worktree-agent-a1abd4be53e43af79'
Browse files at this commit2 changed files +141 -13
crates/app/src/tests/layout.rsmodified+81 -0
| @@ -2974,3 +2974,84 @@ fn the_keys_plate_says_one_noun_and_ends_inside_the_window() { | |||
| 2974 | "the keys plate is no longer capped inside the bench+ledger footprint" | 2974 | "the keys plate is no longer capped inside the bench+ledger footprint" |
| 2975 | ); | 2975 | ); |
| 2976 | } | 2976 | } |
| 2977 | + | ||
| 2978 | + | ||
| 2979 | +/// The ruler's right edge was soup: `bench-select-all` sits `right(4.)` over | ||
| 2980 | +/// the tick band while tick suppression only guarded the LEFT plate, so the | ||
| 2981 | +/// `00:20` label drew straight under the `all` chord. The control's band is | ||
| 2982 | +/// reserved now -- a label whose right edge would enter it is dropped, the | ||
| 2983 | +/// mirror of the left rule. | ||
| 2984 | +#[test] | ||
| 2985 | +fn the_ruler_reserves_a_band_for_its_select_all_control() { | ||
| 2986 | + use crate::ui::bench_stance::{SELECT_ALL_PAD, char_w}; | ||
| 2987 | + use crate::ui::type_scale::{CHORD_METADATA_MIN_PX, FLOOR_PX}; | ||
| 2988 | + let bench = src_text("ui/bench_stance.rs"); | ||
| 2989 | + assert!( | ||
| 2990 | + bench.contains("x + label_w <= bed_w - all_w"), | ||
| 2991 | + "the tick loop no longer keeps the select-all band clear" | ||
| 2992 | + ); | ||
| 2993 | + // The rule itself, with the shipped widths: `all` + `^a` at the chord | ||
| 2994 | + // size, a `00:20` label at the floor size, a 850 px bed. | ||
| 2995 | + let all_w = ("all".len() + "^a".len()) as f32 * char_w(CHORD_METADATA_MIN_PX) + SELECT_ALL_PAD; | ||
| 2996 | + let label_w = "00:20".len() as f32 * char_w(FLOOR_PX); | ||
| 2997 | + let clear = |x: f32| x + label_w <= 850. - all_w; | ||
| 2998 | + assert!(!clear(820.), "a tick at the right edge still draws under `all`"); | ||
| 2999 | + assert!( | ||
| 3000 | + !clear(850. - all_w - label_w + 1.), | ||
| 3001 | + "the band's own edge leaks" | ||
| 3002 | + ); | ||
| 3003 | + assert!(clear(700.), "the rule eats ticks that clear the band"); | ||
| 3004 | +} | ||
| 3005 | + | ||
| 3006 | +/// Clicking `all` selected all AND scrubbed: the control lives inside | ||
| 3007 | +/// `bench-ruler`, whose `on_mouse_down` seeks, and the press reached it (the | ||
| 3008 | +/// playhead jumped 00:00:11:12 -> 00:00:20:14). The scrub refuses the | ||
| 3009 | +/// control's reserved band now -- a `stop_propagation` on the control is what | ||
| 3010 | +/// this looks like at first and it does NOT work: gpui builds the control's | ||
| 3011 | +/// own click out of that same mouse-down, so stopping it drops the selection | ||
| 3012 | +/// (measured live, run 20260909-174243-jZzccm/after-all.png: nothing but the | ||
| 3013 | +/// hover changed). | ||
| 3014 | +#[test] | ||
| 3015 | +fn a_press_on_the_select_all_band_does_not_scrub_the_ruler() { | ||
| 3016 | + use crate::ui::bench_stance::select_all_band; | ||
| 3017 | + let bench = src_text("ui/bench_stance.rs"); | ||
| 3018 | + let at = bench.find(r#".id("bench-ruler")"#).expect("no ruler"); | ||
| 3019 | + let listener = &bench[at..at + bench[at..].find(".children(ticks").expect("its ticks")]; | ||
| 3020 | + assert!( | ||
| 3021 | + listener.contains("bed_w - band") && listener.contains("select_all_band("), | ||
| 3022 | + "the ruler's scrub takes the select-all band's presses again: {listener}" | ||
| 3023 | + ); | ||
| 3024 | + assert!( | ||
| 3025 | + !bench[at..].contains("cx.stop_propagation()"), | ||
| 3026 | + "a press stopped inside the ruler also swallows the control's own click" | ||
| 3027 | + ); | ||
| 3028 | + // The rule the listener runs, at the shipped widths: a 850 px bed, `^a`. | ||
| 3029 | + let band = select_all_band("^a"); | ||
| 3030 | + assert!(band > 30. && band < 70., "the band is not a control's width: {band}"); | ||
| 3031 | + assert!(850. - 4. >= 850. - band, "a press on the control still seeks"); | ||
| 3032 | + assert!(500. < 850. - band, "a press mid-ruler stopped seeking"); | ||
| 3033 | +} | ||
| 3034 | + | ||
| 3035 | +/// DESIGN §4/§5: the hero timecode leads the time band and the ledger carries | ||
| 3036 | +/// position. The ruler's left plate was a third resting copy of the same | ||
| 3037 | +/// reading -- it stays only for the state change it belongs to, a live scrub. | ||
| 3038 | +#[test] | ||
| 3039 | +fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() { | ||
| 3040 | + let bench = src_text("ui/bench_stance.rs"); | ||
| 3041 | + let at = bench | ||
| 3042 | + .find(".child(playhead_tc)") | ||
| 3043 | + .expect("no playhead timecode in the ruler"); | ||
| 3044 | + let before = &bench[..at]; | ||
| 3045 | + let guard = before | ||
| 3046 | + .rfind(".when(player.scrubbing") | ||
| 3047 | + .expect("the ruler plate draws its timecode at rest -- the third copy"); | ||
| 3048 | + assert!( | ||
| 3049 | + before[guard..].matches(".child(").count() <= 2, | ||
| 3050 | + "the scrubbing guard is not the plate's own: {}", | ||
| 3051 | + &before[guard..guard + 200] | ||
| 3052 | + ); | ||
| 3053 | + assert!( | ||
| 3054 | + bench.contains("let plate_w = if player.scrubbing { PLATE_W } else { 0. };"), | ||
| 3055 | + "the ticks still lose the plate's width at rest" | ||
| 3056 | + ); | ||
| 3057 | +} | ||
crates/app/src/ui/bench_stance.rsmodified+60 -13
| @@ -63,6 +63,25 @@ const TICK_MIN_PX: f64 = 64.; | |||
| 63 | const PLATE_W: f32 = 11. * crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX | 63 | const PLATE_W: f32 = 11. * crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX |
| 64 | * type_scale::CHORD_METADATA_MAX_PX | 64 | * type_scale::CHORD_METADATA_MAX_PX |
| 65 | + 9.; | 65 | + 9.; |
| 66 | +/// The reserved right-edge band `bench-select-all` sits in: its own | ||
| 67 | +/// `right(4.)` offset, the `px(3.)` either side of its text and the `gap(3.)` | ||
| 68 | +/// between the label and its chord. The band's text width is measured per | ||
| 69 | +/// render (the chord is keymap-dependent) and added to this. | ||
| 70 | +pub(crate) const SELECT_ALL_PAD: f32 = 4. + 3. + 3. + 3.; | ||
| 71 | +/// The width of that band for a given chord: `all`, the chord, and the | ||
| 72 | +/// padding around them. Read by the tick loop (no label may enter it) and by | ||
| 73 | +/// the ruler's own scrub listener (no press inside it seeks) -- one rule, so | ||
| 74 | +/// the two can never disagree about where the control's edge is. | ||
| 75 | +pub(crate) fn select_all_band(chord: &str) -> f32 { | ||
| 76 | + ("all".len() + chord.chars().count()) as f32 * char_w(type_scale::CHORD_METADATA_MIN_PX) | ||
| 77 | + + SELECT_ALL_PAD | ||
| 78 | +} | ||
| 79 | +/// A mono character's width at `size_px`, from the shared | ||
| 80 | +/// [`crate::layout::LIST_CHAR_W`] calibration (taken at | ||
| 81 | +/// [`type_scale::CHORD_METADATA_MIN_PX`]). | ||
| 82 | +pub(crate) fn char_w(size_px: f32) -> f32 { | ||
| 83 | + crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX * size_px | ||
| 84 | +} | ||
| 66 | /// The pinned track-head column: wide enough for its lane-specific ghost | 85 | /// The pinned track-head column: wide enough for its lane-specific ghost |
| 67 | /// verbs and their compact chords without shrinking their pointer targets. | 86 | /// verbs and their compact chords without shrinking their pointer targets. |
| 68 | const HEAD_W: f32 = 72.; | 87 | const HEAD_W: f32 = 72.; |
| @@ -1278,18 +1297,26 @@ pub(crate) fn render( | |||
| 1278 | // first tick at or after the bed's left edge to the bed's right edge. | 1297 | // first tick at or after the bed's left edge to the bed's right edge. |
| 1279 | // Guarded on `pps > 0` -- a zero scale (no session yet) has no interval | 1298 | // Guarded on `pps > 0` -- a zero scale (no session yet) has no interval |
| 1280 | // that ever advances past the bed's own width, which would loop forever. | 1299 | // that ever advances past the bed's own width, which would loop forever. |
| 1281 | - // FAULT 4: the playhead timecode plate is pinned at `left_0`..`PLATE_W` | 1300 | + // The ruler's two reserved bands, and no tick label may enter either. |
| 1282 | - // over the ruler (DESIGN §5), so a tick whose label would land under it | 1301 | + // Left: the playhead timecode plate, which now shows only while a scrub |
| 1283 | - // is suppressed here rather than drawn and overlapped -- the plate | 1302 | + // drag is live (the hero timecode leads the time band at rest, DESIGN |
| 1284 | - // already owns that lane. | 1303 | + // §4, and the ledger keeps position, §5 -- a third resting copy is the |
| 1304 | + // crowding) -- at rest the band is zero and the ticks have the width | ||
| 1305 | + // back. Right: `bench-select-all`, which used to be drawn straight over | ||
| 1306 | + // the `00:20` label because only the left plate was ever suppressed. | ||
| 1307 | + let plate_w = if player.scrubbing { PLATE_W } else { 0. }; | ||
| 1308 | + let all_chord = player.keymap.chord(ActionId::SelectAll); | ||
| 1309 | + let all_w = select_all_band(&all_chord); | ||
| 1285 | let mut ticks = Vec::new(); | 1310 | let mut ticks = Vec::new(); |
| 1286 | if scale.pps > 0. { | 1311 | if scale.pps > 0. { |
| 1287 | let interval = tick_interval(scale.pps); | 1312 | let interval = tick_interval(scale.pps); |
| 1288 | let mut t = (scale.start / interval).ceil() * interval; | 1313 | let mut t = (scale.start / interval).ceil() * interval; |
| 1289 | while scale.px_at(t) <= bed_w { | 1314 | while scale.px_at(t) <= bed_w { |
| 1290 | let x = scale.px_at(t).max(0.); | 1315 | let x = scale.px_at(t).max(0.); |
| 1291 | - if x >= PLATE_W { | 1316 | + let label = tick_mmss(t); |
| 1292 | - ticks.push((x, tick_mmss(t))); | 1317 | + let label_w = label.chars().count() as f32 * char_w(type_scale::FLOOR_PX); |
| 1318 | + if x >= plate_w && x + label_w <= bed_w - all_w { | ||
| 1319 | + ticks.push((x, label)); | ||
| 1293 | } | 1320 | } |
| 1294 | t += interval; | 1321 | t += interval; |
| 1295 | } | 1322 | } |
| @@ -1331,6 +1358,21 @@ pub(crate) fn render( | |||
| 1331 | .on_mouse_down( | 1358 | .on_mouse_down( |
| 1332 | MouseButton::Left, | 1359 | MouseButton::Left, |
| 1333 | cx.listener(|this, event: &MouseDownEvent, _, cx| { | 1360 | cx.listener(|this, event: &MouseDownEvent, _, cx| { |
| 1361 | + // The reserved right-edge band is `bench-select-all`'s, | ||
| 1362 | + // not the scrub's: a press there used to select all AND | ||
| 1363 | + // seek the playhead under the control (11:12 -> 20:14). | ||
| 1364 | + // The guard lives here rather than as a | ||
| 1365 | + // `stop_propagation` on the control, because stopping | ||
| 1366 | + // the press also swallows the control's own click -- | ||
| 1367 | + // gpui builds a click out of that same mouse-down. | ||
| 1368 | + let bounds = this.ruler.get(); | ||
| 1369 | + let bed_w = f32::from(bounds.size.width).max(1.); | ||
| 1370 | + let band = select_all_band(&this.keymap.chord(ActionId::SelectAll)); | ||
| 1371 | + if f32::from(crate::timeline_math::px_along(event.position.x, bounds)) | ||
| 1372 | + >= bed_w - band | ||
| 1373 | + { | ||
| 1374 | + return; | ||
| 1375 | + } | ||
| 1334 | this.scrubbing = true; | 1376 | this.scrubbing = true; |
| 1335 | this.scrub_to(event.position.x, true, cx); | 1377 | this.scrub_to(event.position.x, true, cx); |
| 1336 | }), | 1378 | }), |
| @@ -1362,11 +1404,15 @@ pub(crate) fn render( | |||
| 1362 | .w(px(1.)) | 1404 | .w(px(1.)) |
| 1363 | .bg(rgb(LAMP_WHITE())), | 1405 | .bg(rgb(LAMP_WHITE())), |
| 1364 | ) | 1406 | ) |
| 1365 | - .child( | 1407 | + .when(player.scrubbing, |ruler| { |
| 1366 | - // The pinned playhead timecode plate, DESIGN §5's own | 1408 | + // The playhead timecode plate, and ONLY while a scrub drag |
| 1367 | - // "playhead's own timecode in a plate at the left edge" -- | 1409 | + // is live: a drag is a state change, which is what a plate |
| 1368 | - // always at `left_0`, never following the scrubbed x, so | 1410 | + // is for. At rest the hero timecode leads the time band |
| 1369 | - // it never overlaps the picture region above it. | 1411 | + // (DESIGN §4) and the ledger carries position (§5); this |
| 1412 | + // was the third resting copy of the same reading. Always | ||
| 1413 | + // at `left_0`, never following the scrubbed x, so it never | ||
| 1414 | + // overlaps the picture region above it. | ||
| 1415 | + ruler.child( | ||
| 1370 | div() | 1416 | div() |
| 1371 | .absolute() | 1417 | .absolute() |
| 1372 | .top_0() | 1418 | .top_0() |
| @@ -1383,7 +1429,8 @@ pub(crate) fn render( | |||
| 1383 | )) | 1429 | )) |
| 1384 | .text_color(rgb(INK1())) | 1430 | .text_color(rgb(INK1())) |
| 1385 | .child(playhead_tc), | 1431 | .child(playhead_tc), |
| 1386 | - ) | 1432 | + ) |
| 1433 | + }) | ||
| 1387 | .child( | 1434 | .child( |
| 1388 | div() | 1435 | div() |
| 1389 | .id("bench-select-all") | 1436 | .id("bench-select-all") |
| @@ -1411,7 +1458,7 @@ pub(crate) fn render( | |||
| 1411 | )) | 1458 | )) |
| 1412 | .text_color(rgb(INK3())) | 1459 | .text_color(rgb(INK3())) |
| 1413 | .child("all") | 1460 | .child("all") |
| 1414 | - .child(player.keymap.chord(ActionId::SelectAll)), | 1461 | + .child(all_chord), |
| 1415 | ), | 1462 | ), |
| 1416 | ) | 1463 | ) |
| 1417 | .child( | 1464 | .child( |