Keep styled runs across incremental paragraph edits
This commit is contained in:
1 parent
4cf64a4d55
commit
36f2aa12d7
4 files changed
+127
-11
No files matched your search
+19
-1
@@ -616,7 +616,13 @@ pub fn edit_json(source: &str, unit: usize) -> Result<String, String> {
|
||||
(next.clone(), engine)
|
||||
}
|
||||
};
|
||||
engine.edit(&next, unit as u64, paragraphs[unit].text.clone());
|
||||
let paragraph = ¶graphs[unit];
|
||||
match inline_runs(¶graph.text, paragraph.font) {
|
||||
Some(runs) => {
|
||||
engine.edit_runs(&next, unit as u64, paragraph.text.clone(), runs);
|
||||
}
|
||||
None => engine.edit(&next, unit as u64, paragraph.text.clone()),
|
||||
}
|
||||
let changed = engine.changed_pages().to_vec();
|
||||
let recomputed = engine.recomputed_pages();
|
||||
let json = render_json(&next, &engine, Some((&changed, recomputed)));
|
||||
@@ -2133,3 +2139,15 @@ mod inline_tests {
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod edit_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn paragraph_edits_keep_inline_runs() {
|
||||
let _ = preview_json("plain start").expect("preview");
|
||||
let json = edit_json("\\textbf{bold} start", 0).expect("edit");
|
||||
assert!(json.contains(r#"font-weight=\"bold\""#), "{json}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user