forked from 1b-agent/opencadstudio-upstream
fix(styles): follow text rename into dimstyle dimtxsty
rename_style_storage and rename_symbol rewrote entities and table rows but left dimtxsty stale, so the next Apply resolved a NULL handle. The follow now lives in both shared functions; the plugin workaround is removed as redundant. Tests: text_rename_follows_dimtxsty drives the manager path (RED first); pre-existing plugin rename test stays green via the shared path. Full suite: 2015 passed / 0 failed / 25 ignored.
This commit is contained in:
1 parent
713930de82
commit
a3742e5668
3 files changed
+43
-8
No files matched your search
@@ -3572,6 +3572,13 @@ fn rename_symbol(doc: &mut codec::CadDocument, ty: &str, old: &str, new: &str) -
|
|||||||
if doc.header.current_text_style_name.eq_ignore_ascii_case(old) {
|
if doc.header.current_text_style_name.eq_ignore_ascii_case(old) {
|
||||||
doc.header.current_text_style_name = new.to_string();
|
doc.header.current_text_style_name = new.to_string();
|
||||||
}
|
}
|
||||||
|
// Dimension styles name their text style; follow the rename (same
|
||||||
|
// as rename_style_storage — see #42).
|
||||||
|
for ds in doc.dim_styles.iter_mut() {
|
||||||
|
if ds.dimtxsty.eq_ignore_ascii_case(old) {
|
||||||
|
ds.dimtxsty = new.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
"DIMSTYLE" => {
|
"DIMSTYLE" => {
|
||||||
|
|||||||
@@ -2160,14 +2160,7 @@ impl<'a> HostSession<'a> {
|
|||||||
}
|
}
|
||||||
self.push_undo("Rename style");
|
self.push_undo("Rename style");
|
||||||
self.app.rename_style_storage(kind_of(kind), &from, &to);
|
self.app.rename_style_storage(kind_of(kind), &from, &to);
|
||||||
if kind == TableStyleKind::Text {
|
// dimtxsty follow lives in rename_style_storage (#42).
|
||||||
// A dimension style names its text style; follow the rename.
|
|
||||||
for dim in self.document_mut().dim_styles.iter_mut() {
|
|
||||||
if dim.dimtxsty.eq_ignore_ascii_case(&from) {
|
|
||||||
dim.dimtxsty = to.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.finish_style_change(kind_of(kind));
|
self.finish_style_change(kind_of(kind));
|
||||||
Ok(handle)
|
Ok(handle)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -610,6 +610,13 @@ impl OpenCADStudio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Dimension styles name their text style; follow the rename so
|
||||||
|
// Apply keeps resolving the handle instead of collapsing to NULL.
|
||||||
|
for ds in doc.dim_styles.iter_mut() {
|
||||||
|
if ds.dimtxsty.eq_ignore_ascii_case(old) {
|
||||||
|
ds.dimtxsty = new.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StyleKind::Dim => {
|
StyleKind::Dim => {
|
||||||
let doc = &mut self.tabs[i].scene.document;
|
let doc = &mut self.tabs[i].scene.document;
|
||||||
@@ -1270,3 +1277,31 @@ impl OpenCADStudio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod rename_follow_tests {
|
||||||
|
// #42: renaming a text style must follow into dimstyle dimtxsty.
|
||||||
|
use super::{OpenCADStudio, StyleKind};
|
||||||
|
use codec::tables::{DimStyle, TextStyle};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn text_rename_follows_dimtxsty() {
|
||||||
|
let mut app = OpenCADStudio::new_for_test();
|
||||||
|
app.automation_op(r#"{"op":"new"}"#);
|
||||||
|
let i = app.active_tab;
|
||||||
|
let mut ts = TextStyle::new("OLD");
|
||||||
|
ts.handle = app.tabs[i].scene.document.allocate_handle();
|
||||||
|
app.tabs[i].scene.document.text_styles.add(ts).unwrap();
|
||||||
|
let mut ds = DimStyle::new("D");
|
||||||
|
ds.dimtxsty = "OLD".to_string();
|
||||||
|
app.tabs[i].scene.document.dim_styles.add(ds).unwrap();
|
||||||
|
app.style_rename = Some("OLD".to_string());
|
||||||
|
app.style_rename_buf = "NEW".to_string();
|
||||||
|
app.style_rename_commit(StyleKind::Text);
|
||||||
|
let dim = app.tabs[i].scene.document.dim_styles.get("D").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
dim.dimtxsty, "NEW",
|
||||||
|
"dimstyle must follow the text-style rename"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user