forge
Explore
Log in

Don't you dare go Hollow

Seams clamp before they persist, and survive a release outside the window

Browse files at this commit

4e57e1ca59066b4c1b2317e25e663a5a97cdbf0eAhmet Kaan GümüşParent: 5480ccb
  • fix
    • seams clamp before they persist, and survive a release outside the window
Show full message
🐛 fix(layout): seams clamp before they persist, and survive a release outside the window

Two defects both best-of-2 arms shared:
- drag_split wrote the raw pointer value, so an over-drag left bench=-1 on
  disk; readers clamped it, but the file read as corrupt. Clamp before write.
- drag_move's outside-window release arm dropped the drag without the save
  that only drag_release performed, so the size reverted on restart.

Grafts from the losing arm: Split::PERSISTED + key() replace two hardcoded
lists that could drift; two persistence tests where there were none; bench
ceiling now guarantees the picture 160px; bench floor 68 -> 80, since 68 was
measured to clip the V1 lane chip and drop A1 entirely.
crates/app/src/layout.rsmodified+60 -24
@@ -396,6 +396,25 @@ pub(crate) enum Split {
396396 Bench,
397397 }
398398
399+impl Split {
400+ /// The two persisted seams -- library/inspector/timeline stay
401+ /// unpersisted, out of this diff's scope, same as before it. Read by
402+ /// [`load_stance_splits`] and [`save_stance_splits`] together so the
403+ /// two can never learn a different set of keys from each other, the
404+ /// gap a sixth region would otherwise fall through silently.
405+ const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench];
406+
407+ fn key(self) -> &'static str {
408+ match self {
409+ Split::Library => "library",
410+ Split::Inspector => "inspector",
411+ Split::Timeline => "timeline",
412+ Split::Dock => "dock",
413+ Split::Bench => "bench",
414+ }
415+ }
416+}
417+
399418 /// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands
400419 /// in for: a seam nobody can put a pointer on is a seam nobody can drag, which
401420 /// is why every editor that ships this draws a strip rather than the hairline
@@ -413,10 +432,11 @@ pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.;
413432 /// timeline is asking on purpose, and the picture still keeps most of a third.
414433 pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7;
415434
416-/// The least the darkroom's bench may be dragged to: a section head and one
417-/// [`LANE_H`] row -- [`bench_stance::render`]'s own floor, read here rather
418-/// than duplicated so the seam and the region it drags never disagree.
419-pub(crate) const BENCH_MIN_H: f32 = 20. + LANE_H;
435+/// The least the darkroom's bench may be dragged to: driven and measured
436+/// against a real project -- below this the V1 lane's own chip clips and
437+/// the A1 lane drops off the bench entirely, which a floor exists to make
438+/// unreachable.
439+pub(crate) const BENCH_MIN_H: f32 = 80.;
420440
421441 /// What a hand has done to the three seams: the size it dragged each panel to,
422442 /// or `None` where nobody has touched one and the window's own share still
@@ -464,32 +484,40 @@ pub(crate) fn stance_splits_config_path() -> std::path::PathBuf {
464484 }
465485
466486 pub(crate) fn load_stance_splits() -> Splits {
487+ load_stance_splits_from(&stance_splits_config_path())
488+}
489+
490+/// One `split=pixels` line per touched seam, read from `path` -- factored out
491+/// of [`load_stance_splits`] so a test can round-trip a scratch file instead
492+/// of the real config.
493+pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits {
467494 let mut splits = Splits::default();
468- if let Ok(text) = std::fs::read_to_string(stance_splits_config_path()) {
495+ if let Ok(text) = std::fs::read_to_string(path) {
469496 for line in text.lines() {
470497 let Some((key, value)) = line.split_once('=') else { continue };
471498 let Ok(px) = value.trim().parse::<f32>() else { continue };
472- match key {
473- "dock" => splits.dock = Some(px),
474- "bench" => splits.bench = Some(px),
475- _ => {}
476- }
499+ let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else {
500+ continue;
501+ };
502+ splits.set(split, px);
477503 }
478504 }
479505 splits
480506 }
481507
482-/// Writes the two sizes a hand has actually dragged -- the legacy three stay
508+/// Writes the sizes a hand has actually dragged -- the legacy three stay
483509 /// unpersisted, as they already were before this diff (out of its scope).
510+/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
511+/// so a region added there needs no second, separately-maintained list here.
484512 pub(crate) fn save_stance_splits(splits: &Splits) {
485- let mut text = String::new();
486- if let Some(d) = splits.dock {
487- text += &format!("dock={d}\n");
488- }
489- if let Some(b) = splits.bench {
490- text += &format!("bench={b}\n");
491- }
492- let path = stance_splits_config_path();
513+ save_stance_splits_to(splits, &stance_splits_config_path());
514+}
515+
516+pub(crate) fn save_stance_splits_to(splits: &Splits, path: &std::path::Path) {
517+ let text: String = Split::PERSISTED
518+ .into_iter()
519+ .filter_map(|split| splits.get(split).map(|px| format!("{}={px}\n", split.key())))
520+ .collect();
493521 if let Some(dir) = path.parent() {
494522 let _ = std::fs::create_dir_all(dir);
495523 }
@@ -515,11 +543,19 @@ pub(crate) fn split_bounds(
515543 // legacy inspector's, so it takes the legacy inspector's own floor
516544 // and ceiling rather than a second pair that would only ever agree.
517545 Split::Dock => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
518- // The bench is the darkroom's own timeline: [`Split::Timeline`]'s
519- // ceiling share, and a floor tall enough for a section head and one
520- // lane row -- `bench_stance::render` draws exactly that pair, and
521- // nothing shorter leaves the lane a whole row.
522- Split::Bench => (BENCH_MIN_H, h * TIMELINE_MAX_SHARE),
546+ // The bench is the darkroom's own timeline, but its ceiling is not
547+ // [`Split::Timeline`]'s window-share one: a bench that swallows
548+ // `TIMELINE_MAX_SHARE` of a 720p window leaves the screen and its
549+ // scale plate only 100px, which is not a picture any more. The
550+ // ceiling instead leaves the screen and time band their own fixed
551+ // 160px -- room for the scale plate, the picture and a sliver of
552+ // letterbox -- and `BENCH_MIN_H` still wins the clamp on anything
553+ // shorter than that.
554+ Split::Bench => (
555+ BENCH_MIN_H,
556+ (h - crate::ui::stance::TIME_BAND_H - crate::ui::stance::LEDGER_H - 160.)
557+ .max(BENCH_MIN_H),
558+ ),
523559 // One whole lane under the chrome, the scrollbar strip's row included
524560 // while there is one to draw ([`timeline_fixed_h`]): a timeline
525561 // shorter than that is a ruler with nothing beneath it. A second
crates/app/src/player/timeline_edit.rsmodified+24 -4
@@ -1518,9 +1518,16 @@ impl Player {
15181518 match event.pressed_button {
15191519 Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx),
15201520 // Released outside the window: the up below never came, so this
1521- // is where the gesture ends. Nothing is owed -- every move has
1522- // already been written.
1523- _ => self.split_drag = None,
1521+ // is where the gesture ends. The size is already written to
1522+ // `self.splits`, but the darkroom's two persisted seams still
1523+ // owe the save `drag_release` would have paid -- without it
1524+ // the drag holds for the session and reverts on restart.
1525+ _ => {
1526+ self.split_drag = None;
1527+ if matches!(split, Split::Dock | Split::Bench) {
1528+ save_stance_splits(&self.splits);
1529+ }
1530+ }
15241531 }
15251532 return;
15261533 }
@@ -1725,8 +1732,21 @@ impl Player {
17251732 window: &mut Window,
17261733 cx: &mut Context<Self>,
17271734 ) {
1735+ let viewport = window.viewport_size();
1736+ let raw = split_drag_size(split, at, viewport);
1737+ // Clamped here, through the same door [`Player::split_px`] draws
1738+ // through, at the one place a hand's pick ever reaches
1739+ // `self.splits` -- so what a later save writes to disk is never a
1740+ // number the seam itself would have refused to draw at. A floor
1741+ // enforced only on read still leaves a `bench=-1` line in the file.
1742+ let lanes = self
1743+ .session
1744+ .as_ref()
1745+ .map_or(2, |session| session.lanes().len());
1746+ let view = self.view();
1747+ let scroll = view.duration > view.span();
17281748 self.splits
1729- .set(split, split_drag_size(split, at, window.viewport_size()));
1749+ .set(split, split_size(split, Some(raw), lanes, viewport, scroll));
17301750 cx.notify();
17311751 }
17321752 }
crates/app/src/tests/layout.rsmodified+37 -5
@@ -1743,9 +1743,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
17431743 #[test]
17441744 fn the_darkroom_seams_stop_before_either_side_disappears() {
17451745 use crate::ui::theme::INSPECTOR_MIN_W;
1746- use crate::{
1747- BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, split_drag_size, split_size,
1748- };
1746+ use crate::{BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds, split_drag_size, split_size};
17491747 use gpui::{point, px, size};
17501748
17511749 let window = size(px(1280.), px(720.));
@@ -1770,15 +1768,18 @@ fn the_darkroom_seams_stop_before_either_side_disappears() {
17701768 split_size(Split::Bench, Some(0.), 2, window, false),
17711769 BENCH_MIN_H
17721770 );
1773- // ...nor the ceiling.
1771+ // ...nor the ceiling. The bench's is not a window-share one -- it leaves
1772+ // the screen and time band a fixed 160px, [`split_bounds`]'s own reason.
17741773 assert_eq!(
17751774 split_size(Split::Dock, Some(9000.), 2, window, false),
17761775 1280. * SIDE_MAX_FRAC
17771776 );
1777+ let (_, bench_max) = split_bounds(Split::Bench, 2, window, false);
17781778 assert_eq!(
17791779 split_size(Split::Bench, Some(9000.), 2, window, false),
1780- 720. * TIMELINE_MAX_SHARE
1780+ bench_max
17811781 );
1782+ assert!(bench_max < 720.);
17821783 // The pointer turned into a size, half a strip off for the same reason
17831784 // the legacy seams read it that way.
17841785 assert_eq!(
@@ -1791,6 +1792,37 @@ fn the_darkroom_seams_stop_before_either_side_disappears() {
17911792 );
17921793 }
17931794
1795+/// A round trip through the file: what is saved is what the next load reads
1796+/// back, one seam touched and the other left at its default -- a scratch
1797+/// path, not the real config, the same isolation `keymap::tests`' own
1798+/// `load_from`/`save_to` already takes.
1799+#[test]
1800+fn a_saved_seam_survives_a_reload() {
1801+ use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to};
1802+
1803+ let dir = engine::scratch::Scratch::dir("edith-stance-splits");
1804+ let path = dir.join("stance-splits");
1805+
1806+ let mut splits = Splits::default();
1807+ splits.set(Split::Dock, 333.);
1808+ save_stance_splits_to(&splits, &path);
1809+ let loaded = load_stance_splits_from(&path);
1810+ assert_eq!(loaded.get(Split::Dock), Some(333.));
1811+ assert_eq!(loaded.get(Split::Bench), None);
1812+}
1813+
1814+/// A missing file leaves every region at its default -- the silent fallback
1815+/// `load_stance_splits`'s doc comment promises.
1816+#[test]
1817+fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
1818+ use crate::{Split, load_stance_splits_from};
1819+
1820+ let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");
1821+ let splits = load_stance_splits_from(&dir.join("nothing-here"));
1822+ assert_eq!(splits.get(Split::Dock), None);
1823+ assert_eq!(splits.get(Split::Bench), None);
1824+}
1825+
17941826 /// Every seam in the main layout has a handle on it, and every region draws
17951827 /// itself at the size that handle sets: a region still measuring itself off the
17961828 /// window's own share is a panel whose divider moves nothing.
crates/app/src/ui/stance.rsmodified+4 -2
@@ -18,8 +18,10 @@ use crate::ui::type_scale::{self, Typeset};
1818 /// Left rail, full height (DESIGN §5).
1919 const SPINE_W: f32 = 56.;
2020 /// Fixed strip under the screen: timecode, transport, cut readout, contact
21-/// strip, Export -- all placeholder at this step.
22-const TIME_BAND_H: f32 = 88.;
21+/// strip, Export -- all placeholder at this step. Kept `pub(crate)` for
22+/// `layout::split_bounds`'s bench ceiling, the same one-door reason
23+/// [`LEDGER_H`] already is.
24+pub(crate) const TIME_BAND_H: f32 = 88.;
2325 /// The bench's untouched height -- [`Split::Bench`]'s own default, read by
2426 /// `layout::split_size` the same way the legacy tree's `library_w`/
2527 /// `inspector_w` feed `Split::Library`/`Split::Inspector`. A hand on the