fix: show newly added draft faders

Synthesize non-writable mixer rows for unsaved targets so added faders and groups remain selected and visibly marked DRAFT with a Save-to-activate explanation.\n\nTests: cargo fmt --all -- --check\nTests: cargo check --workspace --all-targets --all-features\nTests: cargo test -p tui --all-features\nTests: cargo clippy --workspace --all-targets --all-features -- -D warnings
This commit is contained in:
Dandaedre 2026-10-18 12:05:09 +02:00
parent 69975e57dd
commit 86a12fbfe4
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
4 changed files with 80 additions and 11 deletions

View File

@ -112,8 +112,9 @@ orientation, `T` to cycle the theme, and `Q` to open the quit confirmation.
Fader editing exposes capture rules, group membership, separate
controller/Learn/Unlearn actions for volume and mute, size, and visibility.
Add opens a chooser for a new application fader, empty group, or separator.
New faders and groups open directly in the editor; delete asks for confirmation
and removes the selected fader and its unshared target, or the selected separator.
New faders and groups open directly in the editor and remain visible as offline
`DRAFT` rows until Save activates them. Delete asks for confirmation and removes
the selected fader and its unshared target, or the selected separator.
Config → Active profile opens the profile switcher.
Config → Reset active profile provides an emergency return to safe defaults;
confirming it immediately saves and activates the reset and keeps a `.reset.bak`

View File

@ -523,11 +523,14 @@ The selected main-list entry can be moved directly. `A` opens a chooser for an
application fader, group, or separator. Creating an application fader adds its
application target with a deliberately non-matching exact selector, while a new
group starts empty in absolute mode; both operations add a visible layout entry
and open the field-oriented fader editor. `D` confirms removal of either a
separator or a fader with its bindings and layout entry. A fader's application
or group target is also removed when no other fader owns it; applications still
referenced by a group are retained. These compound edits validate and publish as
one draft transaction, so no dangling intermediate configuration is observable.
and open the field-oriented fader editor. Because draft targets do not exist in
the active runtime yet, the TUI synthesizes a non-writable `DRAFT` row labeled
"save to activate" until Save publishes the real online or offline object. `D`
confirms removal of either a separator or a fader with its bindings and layout
entry. A fader's application or group target is also removed when no other fader
owns it; applications still referenced by a group are retained. These compound
edits validate and publish as one draft transaction, so no dangling intermediate
configuration is observable.
The draft must still be saved before it becomes active.
A centered separator dialog edits its name, size, and decoration. Names may be

View File

@ -468,7 +468,9 @@ Dependencies: M8, M2, M1.
editor, IPC/server, and confirmation/cancellation paths are regression-tested.
Mixer `A` now chooses a new application fader, empty absolute group, or
separator. Compound application/group creation adds the target, fader, and
visible layout entry atomically before opening its guided editor. Generic `D`
visible layout entry atomically before opening its guided editor. New targets
remain visible as non-writable DRAFT rows with a Save-to-activate explanation
until activation replaces them with runtime objects. Generic `D`
confirms removal of a fader and its unshared target or a separator. The new
chooser, name editor, and confirmation popup are covered at tiny terminal
sizes, completing the remaining object-creation acceptance.

View File

@ -32,6 +32,7 @@ const CLIENT_IDLE_REFRESH: Duration = Duration::from_millis(250);
const CLIENT_PENDING_REFRESH: Duration = Duration::from_millis(20);
const CLIENT_SHUTDOWN_GRACE: Duration = Duration::from_millis(25);
const MAX_BUFFERED_MUTE_EDGES: usize = 128;
const DRAFT_ITEM_DETAIL: &str = "draft · save to activate";
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum MixerObjectKind {
@ -1503,6 +1504,52 @@ fn mixer_viewport(
(start, extents)
}
fn add_draft_mixer_items(snapshot: &mut MixerSnapshot) {
if !snapshot.configuration.dirty {
return;
}
let targets = snapshot
.configuration
.faders
.iter()
.map(|fader| fader.target.clone())
.collect::<Vec<_>>();
for target in targets {
if snapshot.items.iter().any(|item| item.id == target) {
continue;
}
let label = match target.kind {
MixerObjectKind::Application => snapshot
.configuration
.applications
.iter()
.find(|application| application.id == target.id)
.map(|application| application.label.clone()),
MixerObjectKind::Group => snapshot
.configuration
.groups
.iter()
.find(|group| group.id == target.id)
.map(|group| group.label.clone()),
MixerObjectKind::Output => None,
}
.unwrap_or_else(|| target.id.clone());
snapshot.items.push(MixerItem {
id: target,
label,
detail: DRAFT_ITEM_DETAIL.to_owned(),
gain: None,
gain_mixed: false,
muted: None,
mute_mixed: false,
pending: false,
pickup: Some(PickupStatus::Unavailable),
writable: false,
error: None,
});
}
}
impl<C: MixerClient> LiveTui<C> {
pub fn new(mut client: C) -> io::Result<Self> {
let snapshot = client.snapshot()?;
@ -1517,10 +1564,11 @@ impl<C: MixerClient> LiveTui<C> {
fn from_snapshot(
client: C,
snapshot: MixerSnapshot,
mut snapshot: MixerSnapshot,
theme: ThemeName,
theme_override: bool,
) -> Self {
add_draft_mixer_items(&mut snapshot);
Self {
client,
snapshot,
@ -1576,7 +1624,7 @@ impl<C: MixerClient> LiveTui<C> {
}
}
fn replace_snapshot(&mut self, snapshot: MixerSnapshot) {
fn replace_snapshot(&mut self, mut snapshot: MixerSnapshot) {
let selected_id = self.selected_layout_id();
self.client_error.clone_from(&snapshot.error);
if self.theme_override {
@ -1586,6 +1634,7 @@ impl<C: MixerClient> LiveTui<C> {
} else {
self.theme = snapshot.configuration.theme;
}
add_draft_mixer_items(&mut snapshot);
self.snapshot = snapshot;
self.selected = selected_id
.and_then(|id| self.mixer_rows().iter().position(|row| row.id() == id))
@ -4495,6 +4544,8 @@ impl<C: MixerClient> LiveTui<C> {
};
let state = if item.error.is_some() {
"ERROR"
} else if item.detail == DRAFT_ITEM_DETAIL {
"DRAFT"
} else if item.gain.is_none() {
"OFFLINE"
} else if item.mute_mixed || item.gain_mixed {
@ -4671,7 +4722,9 @@ impl<C: MixerClient> LiveTui<C> {
let percent = item
.gain
.map_or(0, |gain| (gain.clamp(0.0, 1.0) * 100.0).round() as u16);
let state = if item.gain.is_none() {
let state = if item.detail == DRAFT_ITEM_DETAIL {
"DRAFT"
} else if item.gain.is_none() {
"OFFLINE"
} else if item.mute_mixed || item.gain_mixed {
"MIXED"
@ -5376,7 +5429,17 @@ mod tests {
}
app.handle_key_event(press(KeyCode::Enter));
assert!(app.fader_editor.is_some());
assert_eq!(app.mixer_rows()[app.selected].id(), "chat-fader");
app.handle_key_event(press(KeyCode::Esc));
let mut draft_buffer = Buffer::empty(area);
(&app).render(area, &mut draft_buffer);
let draft_rendered = draft_buffer
.content
.iter()
.map(|cell| cell.symbol())
.collect::<String>();
assert!(draft_rendered.contains("DRAFT"));
assert!(draft_rendered.contains("save to activate"));
app.handle_key_event(press(KeyCode::Char('a')));
app.handle_key_event(press(KeyCode::Down));