From 4e57e1ca59066b4c1b2317e25e663a5a97cdbf0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 21 Aug 2026 00:19:25 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(layout):=20seams=20clamp=20b?= =?UTF-8?q?efore=20they=20persist,=20and=20survive=20a=20release=20outside?= =?UTF-8?q?=20the=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 84 ++++++++++++++++++-------- crates/app/src/player/timeline_edit.rs | 28 +++++++-- crates/app/src/tests/layout.rs | 42 +++++++++++-- crates/app/src/ui/stance.rs | 6 +- 4 files changed, 125 insertions(+), 35 deletions(-) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 5276f46..52ebec7 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -396,6 +396,25 @@ pub(crate) enum Split { Bench, } +impl Split { + /// The two persisted seams -- library/inspector/timeline stay + /// unpersisted, out of this diff's scope, same as before it. Read by + /// [`load_stance_splits`] and [`save_stance_splits`] together so the + /// two can never learn a different set of keys from each other, the + /// gap a sixth region would otherwise fall through silently. + const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench]; + + fn key(self) -> &'static str { + match self { + Split::Library => "library", + Split::Inspector => "inspector", + Split::Timeline => "timeline", + Split::Dock => "dock", + Split::Bench => "bench", + } + } +} + /// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands /// in for: a seam nobody can put a pointer on is a seam nobody can drag, which /// 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.; /// timeline is asking on purpose, and the picture still keeps most of a third. pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7; -/// The least the darkroom's bench may be dragged to: a section head and one -/// [`LANE_H`] row -- [`bench_stance::render`]'s own floor, read here rather -/// than duplicated so the seam and the region it drags never disagree. -pub(crate) const BENCH_MIN_H: f32 = 20. + LANE_H; +/// The least the darkroom's bench may be dragged to: driven and measured +/// against a real project -- below this the V1 lane's own chip clips and +/// the A1 lane drops off the bench entirely, which a floor exists to make +/// unreachable. +pub(crate) const BENCH_MIN_H: f32 = 80.; /// What a hand has done to the three seams: the size it dragged each panel to, /// 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 { } pub(crate) fn load_stance_splits() -> Splits { + load_stance_splits_from(&stance_splits_config_path()) +} + +/// One `split=pixels` line per touched seam, read from `path` -- factored out +/// of [`load_stance_splits`] so a test can round-trip a scratch file instead +/// of the real config. +pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits { let mut splits = Splits::default(); - if let Ok(text) = std::fs::read_to_string(stance_splits_config_path()) { + if let Ok(text) = std::fs::read_to_string(path) { for line in text.lines() { let Some((key, value)) = line.split_once('=') else { continue }; let Ok(px) = value.trim().parse::() else { continue }; - match key { - "dock" => splits.dock = Some(px), - "bench" => splits.bench = Some(px), - _ => {} - } + let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else { + continue; + }; + splits.set(split, px); } } splits } -/// Writes the two sizes a hand has actually dragged -- the legacy three stay +/// Writes the sizes a hand has actually dragged -- the legacy three stay /// unpersisted, as they already were before this diff (out of its scope). +/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field, +/// so a region added there needs no second, separately-maintained list here. pub(crate) fn save_stance_splits(splits: &Splits) { - let mut text = String::new(); - if let Some(d) = splits.dock { - text += &format!("dock={d}\n"); - } - if let Some(b) = splits.bench { - text += &format!("bench={b}\n"); - } - let path = stance_splits_config_path(); + save_stance_splits_to(splits, &stance_splits_config_path()); +} + +pub(crate) fn save_stance_splits_to(splits: &Splits, path: &std::path::Path) { + let text: String = Split::PERSISTED + .into_iter() + .filter_map(|split| splits.get(split).map(|px| format!("{}={px}\n", split.key()))) + .collect(); if let Some(dir) = path.parent() { let _ = std::fs::create_dir_all(dir); } @@ -515,11 +543,19 @@ pub(crate) fn split_bounds( // legacy inspector's, so it takes the legacy inspector's own floor // and ceiling rather than a second pair that would only ever agree. Split::Dock => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), - // The bench is the darkroom's own timeline: [`Split::Timeline`]'s - // ceiling share, and a floor tall enough for a section head and one - // lane row -- `bench_stance::render` draws exactly that pair, and - // nothing shorter leaves the lane a whole row. - Split::Bench => (BENCH_MIN_H, h * TIMELINE_MAX_SHARE), + // The bench is the darkroom's own timeline, but its ceiling is not + // [`Split::Timeline`]'s window-share one: a bench that swallows + // `TIMELINE_MAX_SHARE` of a 720p window leaves the screen and its + // scale plate only 100px, which is not a picture any more. The + // ceiling instead leaves the screen and time band their own fixed + // 160px -- room for the scale plate, the picture and a sliver of + // letterbox -- and `BENCH_MIN_H` still wins the clamp on anything + // shorter than that. + Split::Bench => ( + BENCH_MIN_H, + (h - crate::ui::stance::TIME_BAND_H - crate::ui::stance::LEDGER_H - 160.) + .max(BENCH_MIN_H), + ), // One whole lane under the chrome, the scrollbar strip's row included // while there is one to draw ([`timeline_fixed_h`]): a timeline // shorter than that is a ruler with nothing beneath it. A second diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 28fd5dc..878109f 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1518,9 +1518,16 @@ impl Player { match event.pressed_button { Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx), // Released outside the window: the up below never came, so this - // is where the gesture ends. Nothing is owed -- every move has - // already been written. - _ => self.split_drag = None, + // is where the gesture ends. The size is already written to + // `self.splits`, but the darkroom's two persisted seams still + // owe the save `drag_release` would have paid -- without it + // the drag holds for the session and reverts on restart. + _ => { + self.split_drag = None; + if matches!(split, Split::Dock | Split::Bench) { + save_stance_splits(&self.splits); + } + } } return; } @@ -1725,8 +1732,21 @@ impl Player { window: &mut Window, cx: &mut Context, ) { + let viewport = window.viewport_size(); + let raw = split_drag_size(split, at, viewport); + // Clamped here, through the same door [`Player::split_px`] draws + // through, at the one place a hand's pick ever reaches + // `self.splits` -- so what a later save writes to disk is never a + // number the seam itself would have refused to draw at. A floor + // enforced only on read still leaves a `bench=-1` line in the file. + let lanes = self + .session + .as_ref() + .map_or(2, |session| session.lanes().len()); + let view = self.view(); + let scroll = view.duration > view.span(); self.splits - .set(split, split_drag_size(split, at, window.viewport_size())); + .set(split, split_size(split, Some(raw), lanes, viewport, scroll)); cx.notify(); } } diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index a23cc88..499dcc7 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1743,9 +1743,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { #[test] fn the_darkroom_seams_stop_before_either_side_disappears() { use crate::ui::theme::INSPECTOR_MIN_W; - use crate::{ - BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, split_drag_size, split_size, - }; + use crate::{BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds, split_drag_size, split_size}; use gpui::{point, px, size}; let window = size(px(1280.), px(720.)); @@ -1770,15 +1768,18 @@ fn the_darkroom_seams_stop_before_either_side_disappears() { split_size(Split::Bench, Some(0.), 2, window, false), BENCH_MIN_H ); - // ...nor the ceiling. + // ...nor the ceiling. The bench's is not a window-share one -- it leaves + // the screen and time band a fixed 160px, [`split_bounds`]'s own reason. assert_eq!( split_size(Split::Dock, Some(9000.), 2, window, false), 1280. * SIDE_MAX_FRAC ); + let (_, bench_max) = split_bounds(Split::Bench, 2, window, false); assert_eq!( split_size(Split::Bench, Some(9000.), 2, window, false), - 720. * TIMELINE_MAX_SHARE + bench_max ); + assert!(bench_max < 720.); // The pointer turned into a size, half a strip off for the same reason // the legacy seams read it that way. assert_eq!( @@ -1791,6 +1792,37 @@ fn the_darkroom_seams_stop_before_either_side_disappears() { ); } +/// A round trip through the file: what is saved is what the next load reads +/// back, one seam touched and the other left at its default -- a scratch +/// path, not the real config, the same isolation `keymap::tests`' own +/// `load_from`/`save_to` already takes. +#[test] +fn a_saved_seam_survives_a_reload() { + use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to}; + + let dir = engine::scratch::Scratch::dir("edith-stance-splits"); + let path = dir.join("stance-splits"); + + let mut splits = Splits::default(); + splits.set(Split::Dock, 333.); + save_stance_splits_to(&splits, &path); + let loaded = load_stance_splits_from(&path); + assert_eq!(loaded.get(Split::Dock), Some(333.)); + assert_eq!(loaded.get(Split::Bench), None); +} + +/// A missing file leaves every region at its default -- the silent fallback +/// `load_stance_splits`'s doc comment promises. +#[test] +fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { + use crate::{Split, load_stance_splits_from}; + + let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); + let splits = load_stance_splits_from(&dir.join("nothing-here")); + assert_eq!(splits.get(Split::Dock), None); + assert_eq!(splits.get(Split::Bench), None); +} + /// Every seam in the main layout has a handle on it, and every region draws /// itself at the size that handle sets: a region still measuring itself off the /// window's own share is a panel whose divider moves nothing. diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 3ba638d..75fea13 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -18,8 +18,10 @@ use crate::ui::type_scale::{self, Typeset}; /// Left rail, full height (DESIGN ยง5). const SPINE_W: f32 = 56.; /// Fixed strip under the screen: timecode, transport, cut readout, contact -/// strip, Export -- all placeholder at this step. -const TIME_BAND_H: f32 = 88.; +/// strip, Export -- all placeholder at this step. Kept `pub(crate)` for +/// `layout::split_bounds`'s bench ceiling, the same one-door reason +/// [`LEDGER_H`] already is. +pub(crate) const TIME_BAND_H: f32 = 88.; /// The bench's untouched height -- [`Split::Bench`]'s own default, read by /// `layout::split_size` the same way the legacy tree's `library_w`/ /// `inspector_w` feed `Split::Library`/`Split::Inspector`. A hand on the