forge
Explore
Log in

Don't you dare go Hollow

The bench ruler's right edge is a band, not soup

Browse files at this commit

18ad682275bc7635e15ee3b9b10b2fc664ee25cdAhmet Kaan GümüşParent: 2bf7f4a
  • fix
    • the bench ruler's right edge is a band, not soup
Show full message
🐛 fix(app): the bench ruler's right edge is a band, not soup

The `all` control drew straight over the `00:20` tick label and a press on
it selected everything AND scrubbed the playhead under it. The ruler now
keeps a reserved band for the control at its right edge -- no tick label may
enter it, no press inside it seeks -- the mirror of the left plate's rule.

The plate itself is gone at rest: the hero timecode leads the time band
(DESIGN §4) and the ledger carries position (§5), so a third resting copy was
just crowding. It comes back only while a scrub drag is live, which is the
state change a plate is for, and the ticks have its width back otherwise.
crates/app/src/tests/layout.rsmodified+81 -0
@@ -2814,3 +2814,84 @@ fn the_lane_bed_clips_its_clips_at_the_pinned_heads() {
28142814 pinned lane heads: {bed}"
28152815 );
28162816 }
2817+
2818+
2819+/// The ruler's right edge was soup: `bench-select-all` sits `right(4.)` over
2820+/// the tick band while tick suppression only guarded the LEFT plate, so the
2821+/// `00:20` label drew straight under the `all` chord. The control's band is
2822+/// reserved now -- a label whose right edge would enter it is dropped, the
2823+/// mirror of the left rule.
2824+#[test]
2825+fn the_ruler_reserves_a_band_for_its_select_all_control() {
2826+ use crate::ui::bench_stance::{SELECT_ALL_PAD, char_w};
2827+ use crate::ui::type_scale::{CHORD_METADATA_MIN_PX, FLOOR_PX};
2828+ let bench = src_text("ui/bench_stance.rs");
2829+ assert!(
2830+ bench.contains("x + label_w <= bed_w - all_w"),
2831+ "the tick loop no longer keeps the select-all band clear"
2832+ );
2833+ // The rule itself, with the shipped widths: `all` + `^a` at the chord
2834+ // size, a `00:20` label at the floor size, a 850 px bed.
2835+ let all_w = ("all".len() + "^a".len()) as f32 * char_w(CHORD_METADATA_MIN_PX) + SELECT_ALL_PAD;
2836+ let label_w = "00:20".len() as f32 * char_w(FLOOR_PX);
2837+ let clear = |x: f32| x + label_w <= 850. - all_w;
2838+ assert!(!clear(820.), "a tick at the right edge still draws under `all`");
2839+ assert!(
2840+ !clear(850. - all_w - label_w + 1.),
2841+ "the band's own edge leaks"
2842+ );
2843+ assert!(clear(700.), "the rule eats ticks that clear the band");
2844+}
2845+
2846+/// Clicking `all` selected all AND scrubbed: the control lives inside
2847+/// `bench-ruler`, whose `on_mouse_down` seeks, and the press reached it (the
2848+/// playhead jumped 00:00:11:12 -> 00:00:20:14). The scrub refuses the
2849+/// control's reserved band now -- a `stop_propagation` on the control is what
2850+/// this looks like at first and it does NOT work: gpui builds the control's
2851+/// own click out of that same mouse-down, so stopping it drops the selection
2852+/// (measured live, run 20260909-174243-jZzccm/after-all.png: nothing but the
2853+/// hover changed).
2854+#[test]
2855+fn a_press_on_the_select_all_band_does_not_scrub_the_ruler() {
2856+ use crate::ui::bench_stance::select_all_band;
2857+ let bench = src_text("ui/bench_stance.rs");
2858+ let at = bench.find(r#".id("bench-ruler")"#).expect("no ruler");
2859+ let listener = &bench[at..at + bench[at..].find(".children(ticks").expect("its ticks")];
2860+ assert!(
2861+ listener.contains("bed_w - band") && listener.contains("select_all_band("),
2862+ "the ruler's scrub takes the select-all band's presses again: {listener}"
2863+ );
2864+ assert!(
2865+ !bench[at..].contains("cx.stop_propagation()"),
2866+ "a press stopped inside the ruler also swallows the control's own click"
2867+ );
2868+ // The rule the listener runs, at the shipped widths: a 850 px bed, `^a`.
2869+ let band = select_all_band("^a");
2870+ assert!(band > 30. && band < 70., "the band is not a control's width: {band}");
2871+ assert!(850. - 4. >= 850. - band, "a press on the control still seeks");
2872+ assert!(500. < 850. - band, "a press mid-ruler stopped seeking");
2873+}
2874+
2875+/// DESIGN §4/§5: the hero timecode leads the time band and the ledger carries
2876+/// position. The ruler's left plate was a third resting copy of the same
2877+/// reading -- it stays only for the state change it belongs to, a live scrub.
2878+#[test]
2879+fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() {
2880+ let bench = src_text("ui/bench_stance.rs");
2881+ let at = bench
2882+ .find(".child(playhead_tc)")
2883+ .expect("no playhead timecode in the ruler");
2884+ let before = &bench[..at];
2885+ let guard = before
2886+ .rfind(".when(player.scrubbing")
2887+ .expect("the ruler plate draws its timecode at rest -- the third copy");
2888+ assert!(
2889+ before[guard..].matches(".child(").count() <= 2,
2890+ "the scrubbing guard is not the plate's own: {}",
2891+ &before[guard..guard + 200]
2892+ );
2893+ assert!(
2894+ bench.contains("let plate_w = if player.scrubbing { PLATE_W } else { 0. };"),
2895+ "the ticks still lose the plate's width at rest"
2896+ );
2897+}
crates/app/src/ui/bench_stance.rsmodified+60 -13
@@ -63,6 +63,25 @@ const TICK_MIN_PX: f64 = 64.;
6363 const PLATE_W: f32 = 11. * crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX
6464 * type_scale::CHORD_METADATA_MAX_PX
6565 + 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+}
6685 /// The pinned track-head column: wide enough for its lane-specific ghost
6786 /// verbs and their compact chords without shrinking their pointer targets.
6887 const HEAD_W: f32 = 72.;
@@ -1278,18 +1297,26 @@ pub(crate) fn render(
12781297 // first tick at or after the bed's left edge to the bed's right edge.
12791298 // Guarded on `pps > 0` -- a zero scale (no session yet) has no interval
12801299 // 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`
1282- // over the ruler (DESIGN §5), so a tick whose label would land under it
1283- // is suppressed here rather than drawn and overlapped -- the plate
1284- // already owns that lane.
1300+ // The ruler's two reserved bands, and no tick label may enter either.
1301+ // Left: the playhead timecode plate, which now shows only while a scrub
1302+ // drag is live (the hero timecode leads the time band at rest, DESIGN
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);
12851310 let mut ticks = Vec::new();
12861311 if scale.pps > 0. {
12871312 let interval = tick_interval(scale.pps);
12881313 let mut t = (scale.start / interval).ceil() * interval;
12891314 while scale.px_at(t) <= bed_w {
12901315 let x = scale.px_at(t).max(0.);
1291- if x >= PLATE_W {
1292- ticks.push((x, tick_mmss(t)));
1316+ let label = 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));
12931320 }
12941321 t += interval;
12951322 }
@@ -1331,6 +1358,21 @@ pub(crate) fn render(
13311358 .on_mouse_down(
13321359 MouseButton::Left,
13331360 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+ }
13341376 this.scrubbing = true;
13351377 this.scrub_to(event.position.x, true, cx);
13361378 }),
@@ -1362,11 +1404,15 @@ pub(crate) fn render(
13621404 .w(px(1.))
13631405 .bg(rgb(LAMP_WHITE())),
13641406 )
1365- .child(
1366- // The pinned playhead timecode plate, DESIGN §5's own
1367- // "playhead's own timecode in a plate at the left edge" --
1368- // always at `left_0`, never following the scrubbed x, so
1369- // it never overlaps the picture region above it.
1407+ .when(player.scrubbing, |ruler| {
1408+ // The playhead timecode plate, and ONLY while a scrub drag
1409+ // is live: a drag is a state change, which is what a plate
1410+ // is for. At rest the hero timecode leads the time band
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(
13701416 div()
13711417 .absolute()
13721418 .top_0()
@@ -1383,7 +1429,8 @@ pub(crate) fn render(
13831429 ))
13841430 .text_color(rgb(INK1()))
13851431 .child(playhead_tc),
1386- )
1432+ )
1433+ })
13871434 .child(
13881435 div()
13891436 .id("bench-select-all")
@@ -1411,7 +1458,7 @@ pub(crate) fn render(
14111458 ))
14121459 .text_color(rgb(INK3()))
14131460 .child("all")
1414- .child(player.keymap.chord(ActionId::SelectAll)),
1461+ .child(all_chord),
14151462 ),
14161463 )
14171464 .child(