flow: keep the old paragraph direction in the tracked formatting-change snapshot

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-11-15 13:27:34 +01:00
co-authored by Claude Sonnet 5.5
parent 6767c71362
commit 51a35cecb7
2 changed files with 28 additions and 1 deletions
+4 -1
View File
@@ -661,7 +661,10 @@ fn flow_paras_in(doc: &Document, p: &Paragraph, opts: FlowOpts) -> Vec<Para> {
{
(li.list, li.label) = (0, None);
}
let old = Para { kind, list, align: c.old.align, page_break: c.old.page_break_before.unwrap_or(false), ..Default::default() };
// Direction resolved like the current paragraph's: the old properties' own `w:bidi`, else
// the style's.
let rtl = doc.styles.resolve_para(&c.old).bidi;
let old = Para { kind, list, align: c.old.align, rtl, page_break: c.old.page_break_before.unwrap_or(false), ..Default::default() };
Box::new(FmtChange { mark: rev_mark(doc, c.rev), old })
});
}
+24
View File
@@ -94,6 +94,30 @@ fn oldpprops_keep_the_old_paragraph_direction() {
assert_eq!(c.old.bidi, Some(true));
}
#[test]
fn tracked_rtl_to_ltr_change_from_a_document_keeps_the_old_direction() {
use craft_wordmodel::props::{CharProps, ParaProps, PropChange};
use craft_wordmodel::{Revision, RevisionKind};
// Document origin (not RTF): now LTR, before RTL.
let mut p = craft_wordmodel::Paragraph::with_text("A", CharProps::default());
p.props.bidi = Some(false);
p.props.fmt_change = PropChange::boxed(0, ParaProps { bidi: Some(true), ..Default::default() });
let doc = doc_with(vec![p], vec![Revision::new(RevisionKind::Format, "Bob", "2025-01-02T08:05:00Z")]);
let flow = model::from_doc_tracked(&doc);
let Some(FBlock::Para(fp)) = flow.blocks.first() else { panic!("no paragraph") };
assert!(!fp.rtl);
assert!(fp.fmt_change.as_deref().expect("change").old.rtl, "snapshot keeps RTL");
let rtf = export(&doc);
assert!(rtf.contains("{\\*\\oldpprops"), "{rtf}");
let back = import(rtf.as_bytes()).unwrap();
let p = doc_paras(&back)[0];
assert_ne!(p.props.bidi, Some(true), "current direction is LTR");
let change = p.props.fmt_change.as_deref().expect("change read back");
assert_eq!(change.old.bidi, Some(true));
// Reject restores RTL.
assert_eq!(change.old.formatting().bidi, Some(true));
}
#[test]
fn stylesheet_names_take_unicode_escapes() {
// \u116?=t \u105?=i \u116?=t \u108?=l \u101?=e — how Word writes a non-Latin style name.