From d35aa2996497068f5b85366478ae540127446c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 19:40:41 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20persist=20all=20five?= =?UTF-8?q?=20panel=20seam=20sizes,=20not=20just=20dock/bench?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split::PERSISTED now covers library/inspector/timeline alongside dock/bench, and split_drag_owes_save follows the same list so every seam's release actually reaches the config file. load_stance_splits now takes the opening window's size and clamps each loaded seam to its own bound (SIDE_MAX_FRAC, TIMELINE_MAX_SHARE, BENCH_MIN_H) so a file written at one window size can't hand another an illegal layout. --- crates/app/src/layout.rs | 50 +++++++++++++++-------- crates/app/src/main.rs | 2 +- crates/app/src/player/timeline_edit.rs | 16 ++++---- crates/app/src/tests/layout.rs | 55 ++++++++++++++++++++------ 4 files changed, 86 insertions(+), 37 deletions(-) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index c414781..fc72785 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -398,12 +398,19 @@ pub(crate) enum Split { } 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]; + /// Every seam that survives a restart -- all five regions, the file + /// itself the only store (view state stays out of `.edith`, the + /// settled convention). Read by [`load_stance_splits`] and + /// [`save_stance_splits`] together so the set can never learn a + /// different set of keys from each other, the gap a sixth region + /// would otherwise fall through silently. + pub(crate) const PERSISTED: [Split; 5] = [ + Split::Library, + Split::Inspector, + Split::Timeline, + Split::Dock, + Split::Bench, + ]; fn key(self) -> &'static str { match self { @@ -518,23 +525,30 @@ impl Splits { } } -/// Where the darkroom's own two dragged sizes live -- dock and bench, the -/// only pair with a hand on them so far. Same small, silent round trip as -/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves both +/// Where every seam's dragged size lives. Same small, silent round trip as +/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves a seam /// `None`, which [`split_size`] already reads as "give it the window's own /// share". pub(crate) fn stance_splits_config_path() -> std::path::PathBuf { crate::keymap::Keymap::config_path().with_file_name("stance-splits") } -pub(crate) fn load_stance_splits() -> Splits { - load_stance_splits_from(&stance_splits_config_path()) +pub(crate) fn load_stance_splits(window: Size) -> Splits { + load_stance_splits_from(&stance_splits_config_path(), window) } /// 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 { +/// of the real config. `window` is the size the layout is about to be drawn +/// at -- a file written by a wider or taller window can hold a seam past +/// this one's own ceiling, so each value is clamped to it here, before it +/// ever reaches [`Splits`]. [`split_size`] still re-clamps every frame on +/// top of this, but that clamp needs a lane count and a scroll state +/// nothing here has yet; this one runs on the three bounds that do not -- +/// [`SIDE_MAX_FRAC`], [`TIMELINE_MAX_SHARE`] and [`BENCH_MIN_H`] -- so a +/// value this open never reaches even the first frame. +pub(crate) fn load_stance_splits_from(path: &std::path::Path, window: Size) -> Splits { + let (w, h) = (f32::from(window.width), f32::from(window.height)); let mut splits = Splits::default(); if let Ok(text) = std::fs::read_to_string(path) { for line in text.lines() { @@ -547,15 +561,19 @@ pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits { let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else { continue; }; + let px = match split { + Split::Library | Split::Inspector | Split::Dock => px.min(w * SIDE_MAX_FRAC), + Split::Timeline => px.min(h * TIMELINE_MAX_SHARE), + Split::Bench => px.max(BENCH_MIN_H), + }; splits.set(split, px); } } splits } -/// 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, +/// Writes the sizes a hand has actually dragged, one line per seam a hand +/// has touched. 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) { save_stance_splits_to(splits, &stance_splits_config_path()); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index e6c458c..d283b0e 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -931,7 +931,7 @@ fn main() { hw_caps: None, clipboard: None, scrubbing: false, - splits: load_stance_splits(), + splits: load_stance_splits(bounds.size), split_drag: None, trim: None, fade_drag: None, diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 61693d9..3ea0436 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -12,7 +12,7 @@ use crate::*; /// from a live `MouseExitEvent` still cannot be, and is proven by driving /// instead. pub(crate) fn split_drag_owes_save(split: Option) -> bool { - matches!(split, Some(Split::Dock) | Some(Split::Bench)) + split.is_some_and(|split| Split::PERSISTED.contains(&split)) } impl Player { @@ -1750,9 +1750,9 @@ impl Player { 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. 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.splits`, but a persisted seam still owes the save + // `drag_release` would have paid -- without it the drag + // holds for the session and reverts on restart. _ => { self.split_drag = None; if split_drag_owes_save(Some(split)) { @@ -1889,10 +1889,10 @@ impl Player { } if let Some(split) = self.split_drag.take() { self.drag_split(split, event.position, window, cx); - // The darkroom's own two seams outlive the window: written once, - // on the release that ends the gesture, the same small-file - // round trip `ui::dock_stance`'s tab pick uses -- not on every - // sample in between, which `drag_move` above never owed a write. + // Every seam outlives the window: written once, on the release + // that ends the gesture, the same small-file round trip + // `ui::dock_stance`'s tab pick uses -- not on every sample in + // between, which `drag_move` above never owed a write. if split_drag_owes_save(Some(split)) { save_stance_splits(&self.splits); } diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 9e9ad3f..691b6c0 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2135,22 +2135,48 @@ fn the_notice_plate_declares_a_bounded_wrapping_text_layout() { } /// 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. +/// back, all five seams touched -- a scratch path, not the real config, the +/// same isolation `keymap::tests`' own `load_from`/`save_to` already takes. +/// One of the five is written past its own ceiling (the library, past +/// `SIDE_MAX_FRAC` of the window it is loaded back into): a file written at +/// a wider window must not hand a narrower one an illegal layout, so the +/// load clamps it back down rather than reading it verbatim. #[test] fn a_saved_seam_survives_a_reload() { - use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to}; + use crate::{ + BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to, + }; + use gpui::{Pixels, Size, px, size}; let dir = engine::scratch::Scratch::dir("edith-stance-splits"); let path = dir.join("stance-splits"); + let window: Size = size(px(1280.), px(720.)); let mut splits = Splits::default(); + splits.set(Split::Library, 9000.); + splits.set(Split::Inspector, 200.); + splits.set(Split::Timeline, 250.); splits.set(Split::Dock, 333.); + splits.set(Split::Bench, 200.); save_stance_splits_to(&splits, &path); - let loaded = load_stance_splits_from(&path); + let loaded = load_stance_splits_from(&path, window); + assert_eq!( + loaded.get(Split::Library), + Some(1280. * SIDE_MAX_FRAC), + "a library past its own ceiling should clamp to it on load" + ); + assert_eq!(loaded.get(Split::Inspector), Some(200.)); + assert_eq!(loaded.get(Split::Timeline), Some(250.)); assert_eq!(loaded.get(Split::Dock), Some(333.)); - assert_eq!(loaded.get(Split::Bench), None); + assert_eq!(loaded.get(Split::Bench), Some(200.)); + + // A bench saved below its own floor clamps up to it, the same ceiling + // logic mirrored on the one seam whose bound is a minimum. + let mut low_bench = Splits::default(); + low_bench.set(Split::Bench, 1.); + save_stance_splits_to(&low_bench, &path); + let loaded = load_stance_splits_from(&path, window); + assert_eq!(loaded.get(Split::Bench), Some(BENCH_MIN_H)); } /// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends @@ -2158,18 +2184,18 @@ fn a_saved_seam_survives_a_reload() { /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and /// the harness drive `D2` in this session's report for the wiring itself). -/// What *is* checkable here without a window: exactly the two persisted +/// What *is* checkable here without a window: exactly the persisted /// seams owe that save, the same set `Split::PERSISTED` already names, and a /// drag that never started (`None`) owes nothing. #[test] -fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { +fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { use crate::{Split, player::timeline_edit::split_drag_owes_save}; assert!(split_drag_owes_save(Some(Split::Dock))); assert!(split_drag_owes_save(Some(Split::Bench))); - assert!(!split_drag_owes_save(Some(Split::Library))); - assert!(!split_drag_owes_save(Some(Split::Inspector))); - assert!(!split_drag_owes_save(Some(Split::Timeline))); + assert!(split_drag_owes_save(Some(Split::Library))); + assert!(split_drag_owes_save(Some(Split::Inspector))); + assert!(split_drag_owes_save(Some(Split::Timeline))); assert!(!split_drag_owes_save(None)); } @@ -2178,9 +2204,14 @@ fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { #[test] fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { use crate::{Split, load_stance_splits_from}; + use gpui::{Pixels, Size, px, size}; let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); - let splits = load_stance_splits_from(&dir.join("nothing-here")); + let window: Size = size(px(1280.), px(720.)); + let splits = load_stance_splits_from(&dir.join("nothing-here"), window); + assert_eq!(splits.get(Split::Library), None); + assert_eq!(splits.get(Split::Inspector), None); + assert_eq!(splits.get(Split::Timeline), None); assert_eq!(splits.get(Split::Dock), None); assert_eq!(splits.get(Split::Bench), None); }