From 03993057a45a62da80dbca654acc5e75b854b069 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:38:37 +0200 Subject: [PATCH] fix: decode   to a non-breaking space so blank paragraphs survive trimming Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/richclip.rs | 2 +- crates/engine/src/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/richclip.rs b/crates/engine/src/cmd/richclip.rs index dc17474f..8b21b4bb 100644 --- a/crates/engine/src/cmd/richclip.rs +++ b/crates/engine/src/cmd/richclip.rs @@ -313,7 +313,7 @@ fn decode_text(raw: &str) -> String { "gt" => Some('>'), "quot" => Some('"'), "apos" => Some('\''), - "nbsp" => Some(' '), + "nbsp" => Some('\u{a0}'), _ => entity.strip_prefix('#').and_then(numeric_char), }; if let Some(c) = decoded { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index e1d0f179..3e4a459f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -268,6 +268,30 @@ fn html_paste_with_a_source_newline_keeps_its_bold() { assert_eq!(body.paragraphs[0].runs[0].props.bold, Some(true), "{body:?}"); } +#[test] +fn html_paste_keeps_a_blank_nbsp_paragraph_and_the_rich_path() { + for blank in ["

 

", "

 

"] { + let mut s = session(); + let html = format!("

A

{blank}

B

"); + s.execute("edit.paste", &json!({"text": "A\n\u{a0}\nB", "html": html})).unwrap(); + let body = s + .doc() + .unwrap() + .current_slide() + .unwrap() + .shapes + .iter() + .find(|sh| sh.text.as_ref().is_some_and(|t| t.paragraphs.len() == 3)) + .unwrap() + .text + .clone() + .unwrap(); + assert_eq!(body.paragraphs[0].runs[0].text, "A", "{html}: {body:?}"); + assert_eq!(body.paragraphs[0].runs[0].props.bold, Some(true), "{html}: {body:?}"); + assert_eq!(body.paragraphs[2].runs[0].text, "B", "{html}: {body:?}"); + } +} + #[test] fn group_ungroup_roundtrip_positions() { let mut s = session();