fix(tablestyle): ribbon pick writes header so inserts follow it

StyleKey::TableStyle only updated the ribbon mirror, so inserts kept using the header value and resync re-seeded from the mirror. The arm now writes current_table_style_name plus dirty when the style exists, and sync_ribbon_styles seeds from the document like Text/Dim. Tests: tablestyle_ribbon_pick_writes_header_and_dirties plus pick_flows_into_table_insert covering pick-to-dialog (both RED first). Full suite: 1996 passed / 0 failed / 25 ignored.
This commit is contained in:
Karim Jerbi committed 2026-10-09 19:50:17 +01:00
1 parent d3274543b7
commit 2187fe0d34
2 files changed
+66 -2

No files matched your search

+1 -1
View File
@@ -230,7 +230,7 @@ impl OpenCADStudio {
}
})
.collect();
let active_table = self.ribbon.active_table_style.clone();
let active_table = doc.header.current_table_style_name.clone();
let active_table = if table_names.contains(&active_table) {
active_table
} else {
+65 -1
View File
@@ -2342,7 +2342,15 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
self.tabs[i].dirty = true;
}
StyleKey::TableStyle => {
self.ribbon.active_table_style = name;
self.ribbon.active_table_style = name.clone();
let i = self.active_tab;
let found = self.tabs[i].scene.document.objects.values().any(|o| {
matches!(o, codec::objects::ObjectType::TableStyle(ts) if ts.name == name)
});
if found {
self.tabs[i].scene.document.header.current_table_style_name = name;
self.tabs[i].dirty = true;
}
}
}
Task::none()
@@ -4712,6 +4720,62 @@ mod layer_name_target_tests {
}
}
#[cfg(test)]
mod tablestyle_ribbon_tests {
// #45: picking a table style in the ribbon must write the document header
// (like Text/Dim/MLeader), not just the ribbon mirror.
use crate::app::OpenCADStudio;
use crate::modules::StyleKey;
#[test]
fn tablestyle_ribbon_pick_writes_header_and_dirties() {
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let i = app.active_tab;
let mut extra = codec::objects::TableStyle::standard();
extra.name = "EXTRA".to_string();
extra.handle = app.tabs[i].scene.document.allocate_handle();
app.tabs[i]
.scene
.document
.objects
.insert(extra.handle, codec::objects::ObjectType::TableStyle(extra));
app.tabs[i].dirty = false;
let _ = app.on_ribbon_style_changed(StyleKey::TableStyle, "EXTRA".to_string());
assert_eq!(
app.tabs[i].scene.document.header.current_table_style_name,
"EXTRA",
"ribbon pick must reach the document header"
);
assert!(
app.tabs[i].dirty,
"ribbon pick must dirty the tab like its siblings"
);
}
#[test]
fn tablestyle_pick_flows_into_table_insert() {
// End-to-end: ribbon pick → header → insert dialog defaults to the pick.
let mut app = OpenCADStudio::new_for_test();
app.automation_op(r#"{"op":"new"}"#);
let i = app.active_tab;
let mut extra = codec::objects::TableStyle::standard();
extra.name = "EXTRA".to_string();
extra.handle = app.tabs[i].scene.document.allocate_handle();
app.tabs[i]
.scene
.document
.objects
.insert(extra.handle, codec::objects::ObjectType::TableStyle(extra));
let _ = app.on_ribbon_style_changed(StyleKey::TableStyle, "EXTRA".to_string());
app.open_table_insert();
assert_eq!(
app.table_insert.style, "EXTRA",
"insert dialog must default to the ribbon-picked style"
);
}
}
#[cfg(test)]
mod plot_style_ctb_guard_tests {
use crate::app::OpenCADStudio;