mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
23 lines
853 B
Rust
23 lines
853 B
Rust
//! The notes text model: typing keeps the formatting around it.
|
|
|
|
use craft_text::ui::notes::{NotesParagraph, NotesRun, NotesText};
|
|
use craft_ui::testing::trial;
|
|
|
|
fn run(text: &str, bold: bool) -> NotesRun {
|
|
NotesRun::new(text).bold(bold)
|
|
}
|
|
|
|
fn paragraph(runs: Vec<NotesRun>) -> NotesParagraph {
|
|
NotesParagraph::new(runs)
|
|
}
|
|
|
|
#[trial]
|
|
fn typed_replaces_the_span_between_the_common_prefix_and_suffix() {
|
|
let notes = NotesText::new(vec![paragraph(vec![run("bold", true), run(" plain", false)])]);
|
|
let replaced = notes.typed("bXYZ plain").expect("a prefix and a suffix are shared");
|
|
assert_eq!(replaced.paragraphs[0].runs, vec![run("bXYZ", true), run(" plain", false)]);
|
|
let split = notes.typed("bold\r\n plain").expect("shares both ends");
|
|
assert_eq!(split.plain(), "bold\n plain");
|
|
assert_eq!(split.paragraphs.len(), 2);
|
|
}
|