| ... | ... | @@ -3320,3 +3320,54 @@ fn restyle_refuses_renames_and_missing_styles() { |
| 3320 | 3320 | assert!(section.page(space).unwrap() == page); |
| 3321 | 3321 | } |
| 3322 | 3322 | } |
| 3323 | |
| 3324 | /// An equation's paragraph restyled in italics, then lowered back to the page before it, as |
| 3325 | /// undo does: the math runs a style left italic go back whole, since they refuse formatting. |
| 3326 | #[test] |
| 3327 | fn a_restyled_equation_lowers_back() { |
| 3328 | let (_, source) = SOURCES.iter().find(|(name, _)| *name == "math").unwrap(); |
| 3329 | let space = pages(source)[0]; |
| 3330 | let arena = Arena::default(); |
| 3331 | let mut section = Section::open(&arena, source.to_vec()).unwrap(); |
| 3332 | let before = section.page(space).unwrap(); |
| 3333 | let paragraph = model::lists(&before) |
| 3334 | .into_iter() |
| 3335 | .flat_map(|(_, _, list)| list.iter()) |
| 3336 | .find(|paragraph| { |
| 3337 | paragraph |
| 3338 | .text() |
| 3339 | .is_some_and(|text| crate::page::Math::is_equation(&text.text)) |
| 3340 | }) |
| 3341 | .unwrap() |
| 3342 | .id; |
| 3343 | let style = PageOp::Style { |
| 3344 | paragraph, |
| 3345 | style: id(), |
| 3346 | definition: Definition { |
| 3347 | kind: Kind::Style { |
| 3348 | name: Some("Quote".into()), |
| 3349 | next: None, |
| 3350 | }, |
| 3351 | format: Format { |
| 3352 | italic: Some(true), |
| 3353 | ..Default::default() |
| 3354 | }, |
| 3355 | }, |
| 3356 | }; |
| 3357 | let edit = |ops: Vec<PageOp>| Edit { |
| 3358 | at: AT, |
| 3359 | ops: ops.into_iter().map(|op| Op::Page { space, op }).collect(), |
| 3360 | }; |
| 3361 | section.apply("Author", &edit(vec![style])).unwrap(); |
| 3362 | let styled = section.page(space).unwrap(); |
| 3363 | section |
| 3364 | .apply("Author", &edit(lower_page(&styled, &before).unwrap())) |
| 3365 | .unwrap(); |
| 3366 | let after = section.page(space).unwrap(); |
| 3367 | assert_eq!( |
| 3368 | normalize(&after), |
| 3369 | normalize(&before), |
| 3370 | "{}", |
| 3371 | first_difference(&normalize(&after), &normalize(&before)) |
| 3372 | ); |
| 3373 | } |