fix(M9.4): preserve saved fader order during TOML serialization

Normalize layout table source positions when moving entries or inserting separators. Parsed TOML previously restored old order despite successful edits, causing optimistic swaps to snap back after reload. Cover repeated moves, comments, hidden entries, and IPC refresh/save/server restart.

Verification: reproduced failure with save/reparse regression before fix. PASS: cargo test -p fader-config --test editor; cargo test -p fader_master --lib persisted_layout_reorders; cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features --quiet (2 opt-in hardware tests ignored); cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; cargo check --workspace; cargo check --workspace --no-default-features; cargo check -p midi --no-default-features --features midir; cargo check -p volume_lib --no-default-features --features pulse.
This commit is contained in:
Dandaedre 2026-10-16 19:17:30 +02:00
parent 4e0d3e99a7
commit a7587d45de
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
5 changed files with 153 additions and 3 deletions

View File

@ -478,7 +478,12 @@ MIDI bindings, or saved state. Profiles without an explicit layout synthesize
one visible entry for every declared fader in declaration order. Validation
rejects duplicate layout IDs, duplicate fader references, and dangling fader
references. Each fader layout entry also stores a `slim`, `standard`, or `thick`
density. Omitted density defaults to `standard` for existing profiles. Vertical
density. Layout moves and separator insertion normalize the TOML tables' source
positions to a shared layout anchor before serialization. Parsed tables retain
their old source positions, so vector order alone does not survive serialization;
the normalized anchor preserves the requested order and each entry's comments
across Save and server restart.
Omitted density defaults to `standard` for existing profiles. Vertical
mode keeps the stacked card layout: Slim is a single terminal row while the
other sizes retain progressively more detail. Horizontal mode uses side-by-side
console-style fader strips with bottom-up meters, state, percentage, pickup

View File

@ -425,7 +425,7 @@ pickup_tolerance = 0.02
separator["id"] = value(id);
separator["label"] = value(label);
ordered.insert(position.min(ordered.len()), separator);
*tables = ordered.into_iter().collect();
replace_layout_order(tables, ordered);
Ok(())
})
}
@ -524,7 +524,7 @@ pickup_tolerance = 0.02
})?;
let entry = ordered.remove(index);
ordered.insert(position.min(ordered.len()), entry);
*tables = ordered.into_iter().collect();
replace_layout_order(tables, ordered);
Ok(())
})
}
@ -717,6 +717,19 @@ fn materialize_mixer_layout(document: &mut DocumentMut) -> Result<&mut ArrayOfTa
Ok(tables)
}
fn replace_layout_order(tables: &mut ArrayOfTables, mut ordered: Vec<Table>) {
// Parsed tables carry source positions, and toml_edit sorts by those when
// serializing. Reordering the vector alone therefore undoes a move on
// save/preview. Give this flat layout array one common source anchor so
// stable serialization follows its new order, retaining each table's decor.
if let Some(anchor) = ordered.iter().filter_map(Table::position).min() {
for table in &mut ordered {
table.set_position(anchor);
}
}
*tables = ordered.into_iter().collect();
}
fn layout_entry_id(table: &Table) -> Option<&str> {
match table.get("kind").and_then(Item::as_str) {
Some("fader") => table.get("fader").and_then(Item::as_str),

View File

@ -245,6 +245,9 @@ fn mixer_layout_draft_reorders_separators_and_retains_hidden_faders() {
draft
.set_fader_density("media-fader", fader_config::FaderDensity::Thick)
.expect("fader density must be editable");
// Real sessions reopen a saved layout: parsed tables retain source positions.
let saved = draft.finish().unwrap();
let mut draft = ProfileDocument::parse(&saved).unwrap();
draft
.move_layout_entry("media-fader", 0)
.expect("hidden fader must remain reorderable");
@ -290,6 +293,73 @@ fn mixer_layout_draft_reorders_separators_and_retains_hidden_faders() {
);
}
#[test]
fn saved_layout_moves_and_insertions_survive_repeated_reloads() {
let source = format!(
"{PROFILE}\n\
[[faders]]\nid = \"other-fader\"\ntarget = {{ kind = \"group\", id = \"media\" }}\npickup = true\npickup_tolerance = 0.02\n\
# first fader comment\n[[mixer_layout]]\nkind = \"fader\"\nfader = \"media-fader\"\ndensity = \"slim\"\n\
# separator comment\n[[mixer_layout]]\nkind = \"separator\"\nid = \"heading\"\nlabel = \"Heading\"\n\
# hidden fader comment\n[[mixer_layout]]\nkind = \"fader\"\nfader = \"other-fader\"\nhidden = true\n"
);
let mut draft = ProfileDocument::parse(&source).unwrap();
let ids = |draft: &ProfileDocument| {
draft
.preview()
.unwrap()
.mixer_layout()
.iter()
.map(|entry| match entry {
MixerLayoutEntry::Fader { fader, .. } => fader.clone(),
MixerLayoutEntry::Separator { id, .. } => id.clone(),
})
.collect::<Vec<_>>()
};
for (id, position, expected) in [
("media-fader", 2, ["heading", "other-fader", "media-fader"]),
("media-fader", 0, ["media-fader", "heading", "other-fader"]),
("other-fader", 0, ["other-fader", "media-fader", "heading"]),
("heading", 1, ["other-fader", "heading", "media-fader"]),
] {
draft.move_layout_entry(id, position).unwrap();
assert_eq!(ids(&draft), expected);
draft = ProfileDocument::parse(&draft.finish().unwrap()).unwrap();
assert_eq!(ids(&draft), expected);
}
draft
.add_separator("new-heading", "New heading", 0)
.unwrap();
draft = ProfileDocument::parse(&draft.finish().unwrap()).unwrap();
assert_eq!(
ids(&draft),
["new-heading", "other-fader", "heading", "media-fader"]
);
let saved = draft.source();
for comment in [
"first fader comment",
"separator comment",
"hidden fader comment",
] {
assert_eq!(saved.matches(comment).count(), 1);
}
let profile = draft.preview().unwrap();
assert!(matches!(
&profile.mixer_layout()[1],
MixerLayoutEntry::Fader { hidden: true, .. }
));
assert!(matches!(
&profile.mixer_layout()[3],
MixerLayoutEntry::Fader {
density: fader_config::FaderDensity::Slim,
..
}
));
assert_eq!(
profile.bindings(),
fader_config::Profile::parse(PROFILE).unwrap().bindings()
);
}
#[test]
fn selector_and_binding_edits_preserve_unrelated_capture_and_actions() {
let mut draft = ProfileDocument::parse(PROFILE).unwrap();

View File

@ -1071,6 +1071,63 @@ mod tests {
);
}
#[test]
fn persisted_layout_reorders_through_ipc_after_each_server_restart() {
let root = tempdir().unwrap();
let source = format!(
"{}\n[[faders]]\nid = \"second-fader\"\ntarget = {{ kind = \"group\", id = \"media\" }}\npickup = true\npickup_tolerance = 0.02\n\
[[mixer_layout]]\nkind = \"fader\"\nfader = \"media-fader\"\n\
[[mixer_layout]]\nkind = \"fader\"\nfader = \"second-fader\"\n",
include_str!("../../examples/profiles/desktop.toml")
);
let profile_path = root.path().join("desktop.toml");
fs::write(&profile_path, source).unwrap();
for destination in [1, 0, 1] {
let source = fs::read_to_string(&profile_path).unwrap();
let mut server = LocalServer::pulse(
root.path().join("control.sock"),
Gain::UNITY,
ProfileDocument::parse(&source).unwrap(),
profile_path.clone(),
root.path().join("config.toml"),
root.path().join("state.toml"),
)
.unwrap();
for command in [
RequestCommand::EditConfiguration {
expected_revision: 0,
edit: crate::ipc::ConfigurationEdit::MoveLayoutEntry {
id: "media-fader".into(),
position: destination,
},
},
RequestCommand::Snapshot,
RequestCommand::SaveConfiguration {
expected_revision: 1,
},
RequestCommand::Snapshot,
] {
let response = direct_request(&mut server, command);
let ResponseResult::Snapshot { snapshot } = response.result else {
panic!("layout request failed: {:?}", response.result);
};
assert!(
matches!(
&snapshot.configuration.mixer_layout[destination],
crate::ipc::MixerLayoutEntry::Fader { fader, .. } if fader == "media-fader"
),
"confirmed layout reverted at destination {destination}"
);
}
let saved =
fader_config::Profile::parse(&fs::read_to_string(&profile_path).unwrap()).unwrap();
assert!(matches!(
&saved.mixer_layout()[destination],
fader_config::MixerLayoutEntry::Fader { fader, .. } if fader == "media-fader"
));
}
}
fn direct_request(
server: &mut LocalServer,
command: crate::ipc::RequestCommand,

View File

@ -400,6 +400,11 @@ Dependencies: M8, M2, M1.
Config also persists pickup-status presentation as Detailed, Compact,
Symbol, Color, or Hidden. Both mixer orientations share the same state
mapping, and hiding the indicator does not disable pickup protection.
Reordering saved layouts now resets TOML source-order metadata: parsed table
positions previously undid accepted moves during serialization, causing the
optimistic TUI swap to snap back. Regression tests cover repeated file reloads,
both move directions, separator insertion, hidden entries and comments, plus
IPC edit/refresh/Save and reordering after server restart.
- [x] **M9.5 Guided fader editor:** replace pipe-delimited table commands with a
selected-fader form. Application faders edit capture field/mode/pattern;
groups select eligible application faders and show the absolute group mode;