Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 3dcef087dd fix(docx): a text box in a hyperlinked nested group survives an edit (repin regression)
craft-libs 6a46b44449 keeps a hyperlinked nested group as a nested
InlineObject::Group. WordCraft looks one level deep, so prune_text_boxes
dropped the nested box's story on the first edit. The bridge now lifts nested
members into the parent group, offsets composed, as the reader does for
unlinked groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-29 02:42:58 +00:00
4 changed files with 45 additions and 20 deletions
+22 -5
View File
@@ -100,18 +100,35 @@ fn object_value_from_shared(
float: convert(float)?,
ch_w,
ch_h,
children: children.into_iter().map(|c| group_child_value_from_shared(c, graphics)).collect::<Result<_, _>>()?,
children: group_children_from_shared(children, graphics)?,
canvas: canvas.map(convert).transpose()?,
}),
other => convert(other),
}
}
fn group_child_value_from_shared(
source: craft_wordmodel::para::GroupChild,
/// A group's members. The shared reader keeps a hyperlinked nested group whole; WordCraft's
/// text box, layout and edit code looks one level deep, so lift its members into this group
/// (their offsets composed, scaled from the nested group's child space), as the reader does for
/// an unlinked one. The nested group's own link is dropped.
// lean: nested groups are flattened until WordCraft supports them (follow-up issue).
fn group_children_from_shared(
children: Vec<craft_wordmodel::para::GroupChild>,
graphics: &mut GraphicCache,
) -> Result<wordcraft_doc::para::GroupChild, DocxError> {
Ok(wordcraft_doc::para::GroupChild { x: source.x, y: source.y, obj: object_value_from_shared(source.obj, graphics)? })
) -> Result<Vec<wordcraft_doc::para::GroupChild>, DocxError> {
let mut out = Vec::with_capacity(children.len());
for c in children {
let (x, y) = (c.x, c.y);
match object_value_from_shared(c.obj, graphics)? {
wordcraft_doc::para::InlineObject::Group { w, h, ch_w, ch_h, children, .. } => {
let (kx, ky) = (if ch_w > 0.0 { w / ch_w } else { 1.0 }, if ch_h > 0.0 { h / ch_h } else { 1.0 });
// `children` is already flat: the recursion converted the nested group first.
out.extend(children.into_iter().map(|m| wordcraft_doc::para::GroupChild { x: x + m.x * kx, y: y + m.y * ky, obj: m.obj }));
}
obj => out.push(wordcraft_doc::para::GroupChild { x, y, obj }),
}
}
Ok(out)
}
fn table_value_from_shared(source: craft_wordmodel::table::Table, graphics: &mut GraphicCache) -> Result<wordcraft_doc::table::Table, DocxError> {
+20
View File
@@ -265,3 +265,23 @@ fn story_shared_by_many_shapes_is_written_once() {
// fallback. The other shapes do not repeat it.
assert_eq!(xml.matches(text.as_str()).count(), 2);
}
#[test]
fn text_box_in_a_linked_nested_group_survives_pruning() {
// The shared reader keeps a hyperlinked nested group whole; the box inside must still be
// reachable (`text_boxes` looks one level deep), or the first edit's prune deletes its story.
let inner = r#"<wpg:grpSp><wpg:cNvPr id="3" name="Inner"><a:hlinkClick r:id="rId9"/></wpg:cNvPr><wpg:cNvGrpSpPr/><wpg:grpSpPr><a:xfrm><a:off x="635000" y="0"/><a:ext cx="635000" cy="635000"/><a:chOff x="0" y="0"/><a:chExt cx="635000" cy="635000"/></a:xfrm></wpg:grpSpPr><wps:wsp><wps:cNvPr id="4" name="Box"/><wps:cNvSpPr txBox="1"/><wps:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="635000" cy="635000"/></a:xfrm><a:prstGeom prst="rect"/></wps:spPr><wps:txbx><w:txbxContent><w:p><w:r><w:t>Inside</w:t></w:r></w:p></w:txbxContent></wps:txbx><wps:bodyPr/></wps:wsp></wpg:grpSp>"#;
let doc = format!(
r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"><w:body><w:p><w:r><w:drawing><wp:inline><wp:extent cx="1270000" cy="635000"/><wp:docPr id="1" name="Outer"/><a:graphic><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"><wpg:wgp><wpg:cNvGrpSpPr/><wpg:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="1270000" cy="635000"/><a:chOff x="0" y="0"/><a:chExt cx="1270000" cy="635000"/></a:xfrm></wpg:grpSpPr>{inner}</wpg:wgp></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p></w:body></w:document>"#
);
let rels = br#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>"#;
let doc_rels = br#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="https://example.com/" TargetMode="External"/></Relationships>"#;
let bytes = zip(&[("_rels/.rels", rels), ("word/document.xml", doc.as_bytes()), ("word/_rels/document.xml.rels", doc_rels)]);
let mut d = wordcraft_docx::read(&bytes).unwrap();
assert_eq!(boxes(&d).len(), 1);
// What every mutating command does after it runs.
d.prune_text_boxes();
assert_eq!(boxes(&d).len(), 1, "the nested box lost its story");
let xml = document_xml(&wordcraft_docx::write(&d).unwrap());
assert!(xml.contains("Inside"), "{xml}");
}
+3 -3
View File
@@ -6,7 +6,7 @@ use std::borrow::Cow;
use craft::behavior::{Mixed, SelectionChange, keyed};
use craft::color_ui::ui::ColorPickerTab;
use craft::pages::ui::table::{BorderEdges, EdgeKey, EdgeLook, EdgePicker, EdgeSize, SampleArea};
use craft::pages::ui::table::{BorderEdges, EdgeKey, EdgeLook, EdgePicker, SampleArea};
use craft::text::ui::DocUnit;
use craft::text::ui::ruler::{TabAlign as UiAlign, TabLeader as UiLeader, TabStop as UiStop};
use craft::text::ui::tabs_dialog::{MAX_STOPS, TabStopsDialog, TabStopsResult};
@@ -518,7 +518,7 @@ fn lines(ui: &mut Ui, key: &'static str, l: &mut LineForm, area: SampleArea, fil
Stack::new().show(ui, |ui, _| {
let mut edges = l.edges(between);
let sample = EdgeLook::sample(area, fill.map(srgba));
let picker = EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut edges)).look(sample).preview(EdgeSize::Sample);
let picker = EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut edges)).look(sample);
let picker = if between { picker.paragraph() } else { picker };
picker.show(ui);
l.take_edges(edges, between);
@@ -572,7 +572,7 @@ impl WordForm for BordersForm {
let mut none = BorderEdges::default();
let area = if self.fill_to_text { SampleArea::Text } else { SampleArea::Paragraph };
let sample = EdgeLook::sample(area, Rgb::parse(&self.fill).map(srgba));
EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut none)).look(sample).preview(EdgeSize::Sample).enabled(false).show(ui);
EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut none)).look(sample).enabled(false).show(ui);
Self::apply_to(ui, &mut self.fill_to_text, word(tl!("Paragraph")), word(tl!("Text")));
}
}
-12
View File
@@ -2340,18 +2340,6 @@ fn dialog_previews_are_drawn_larger_than_a_control() {
);
}
}
/// #7977: Borders and Shading draws its edge preview at sample size, not as a thumbnail.
#[test]
fn borders_preview_is_larger_than_a_thumbnail() {
use egui::accesskit::Role;
let mut h = app_harness(app_with("Lanterns"));
h.state_mut().run("ui.dialog", json!({"name": "borders"})).unwrap();
h.run_steps(6);
let preview = h.get_by_role_and_label(Role::Group, "Preview").rect();
let button = h.get_by_role_and_label(Role::Button, "Cancel").rect();
assert!(preview.height() > 2.0 * button.height(), "the preview is {}pt high beside a {}pt button", preview.height(), button.height());
}
/// #7982: Custom Properties' hint wraps inside the dialog instead of running under the Cancel button.
#[test]
fn custom_properties_hint_does_not_run_under_the_buttons() {