mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Type: Convert To Point Type keeps forced line breaks
A line that starts after a forced line break (U+2028) is no longer taken for a soft wrap, so converting area type to point type no longer adds a paragraph return after each forced line break.
This commit is contained in:
@@ -786,8 +786,9 @@ fn to_point(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let plain = t.plain_text();
|
||||
let baseline = lay.lines.first().map(|l| l.baseline).unwrap_or(fb.y0 + t.first_style().size * 0.8);
|
||||
// Soft wraps → explicit breaks (replace the space before the wrap when there is one).
|
||||
let mut breaks: Vec<usize> =
|
||||
lay.lines.iter().skip(1).map(|l| l.start).filter(|&b| b > 0 && plain.as_bytes().get(b - 1) != Some(&b'\n')).collect();
|
||||
// A line after a paragraph return or a forced line break (U+2028) already starts there.
|
||||
let hard = |b: usize| plain.get(..b).is_some_and(|s| s.ends_with(['\n', '\u{2028}']));
|
||||
let mut breaks: Vec<usize> = lay.lines.iter().skip(1).map(|l| l.start).filter(|&b| b > 0 && !hard(b)).collect();
|
||||
breaks.sort_unstable();
|
||||
breaks.dedup();
|
||||
for b in breaks.into_iter().rev() {
|
||||
|
||||
@@ -4088,6 +4088,17 @@ fn area_to_point_turns_wraps_into_breaks() {
|
||||
assert_eq!(txt.replace('\n', " "), "one two three four five six");
|
||||
}
|
||||
|
||||
/// Convert To Point Type keeps the lines that a paragraph return or a forced line break (U+2028)
|
||||
/// starts as they are: neither gets a paragraph return added after it.
|
||||
#[test]
|
||||
fn area_to_point_keeps_forced_line_breaks() {
|
||||
let mut s = session();
|
||||
let a = id_of(&s.execute("text.create", &json!({"x": 0, "y": 0, "text": "ab\u{2028}c\nd", "area": {"width": 300, "height": 200}})).unwrap());
|
||||
sel(&mut s, &[a]);
|
||||
s.execute("type.convertToPointType", &json!({})).unwrap();
|
||||
assert_eq!(plain(&s, a), "ab\u{2028}c\nd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placeholder_and_insert_characters() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user