mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-16 23:24:42 +00:00
Merge pull request #1097 from Silvertree2010/fix/h1120-text-set-keeps-a-stray-carriage
This commit is contained in:
commit
a7876aab54
2 files changed
+18
No files matched your search
@@ -94,6 +94,23 @@ fn text_editing_flow() {
|
||||
assert_eq!(s.doc().unwrap().selection.shapes.len(), 1);
|
||||
}
|
||||
|
||||
/// `text.set` treats CRLF (or a lone CR) as one paragraph break and keeps no `\r` in the text.
|
||||
#[test]
|
||||
fn text_set_crlf_makes_clean_paragraphs() {
|
||||
let mut s = session();
|
||||
let r = s.execute("insert.textBox", &json!({"text": "x"})).unwrap();
|
||||
let id = r["id"].as_u64().unwrap();
|
||||
s.execute("text.set", &json!({"id": id, "text": "one\r\ntwo"})).unwrap();
|
||||
let t = s.execute("text.get", &json!({"id": id})).unwrap();
|
||||
assert_eq!(t["paragraphs"][0]["text"], "one");
|
||||
assert_eq!(t["paragraphs"][1]["text"], "two");
|
||||
assert_eq!(t["text"], "one\ntwo");
|
||||
// A lone CR (old Mac line ends) is a paragraph break too, as `edit::insert` treats it.
|
||||
s.execute("text.set", &json!({"id": id, "text": "a\rb"})).unwrap();
|
||||
let t = s.execute("text.get", &json!({"id": id})).unwrap();
|
||||
assert_eq!(t["text"], "a\nb");
|
||||
}
|
||||
|
||||
/// Cut with only a caret copies nothing, so it must not delete the character after the caret.
|
||||
#[test]
|
||||
fn cut_with_only_a_caret_changes_nothing() {
|
||||
|
||||
@@ -603,6 +603,7 @@ pub struct TextBody {
|
||||
|
||||
impl TextBody {
|
||||
pub fn from_text(text: &str) -> Self {
|
||||
let text = text.replace("\r\n", "\n").replace('\r', "\n");
|
||||
TextBody { paragraphs: text.split('\n').map(Paragraph::new).collect(), ..Default::default() }
|
||||
}
|
||||
/// Plain text with `\n` between paragraphs.
|
||||
|
||||
Reference in new issue
Block a user