diff --git a/moli-renderer-v8/src/context_bootstrap/range_algorithms/text.rs b/moli-renderer-v8/src/context_bootstrap/range_algorithms/text.rs index de35767202..fb2350f0a7 100644 --- a/moli-renderer-v8/src/context_bootstrap/range_algorithms/text.rs +++ b/moli-renderer-v8/src/context_bootstrap/range_algorithms/text.rs @@ -498,15 +498,11 @@ fn append_rendered_text_node(out: &mut String, text: &str) { let trailing = &text[last_non_ws..]; let body = collapse_whitespace(&text[first_non_ws..last_non_ws]); - if leading.chars().any(char::is_whitespace) - && !leading.contains('\n') - && !out.is_empty() - && !out.ends_with([' ', '\n']) - { + if leading.chars().any(char::is_whitespace) && !out.is_empty() && !out.ends_with([' ', '\n']) { out.push(' '); } out.push_str(&body); - if trailing.chars().any(char::is_whitespace) && !trailing.contains('\n') { + if trailing.chars().any(char::is_whitespace) { out.push(' '); } } diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs index 98af120a22..8e32814f79 100644 --- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs +++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs @@ -4475,7 +4475,11 @@ fn selection_to_string_uses_rendered_native_range_projection() { const contentHidden = document.createElement("div"); contentHidden.setAttribute("style", "content-visibility: hidden"); contentHidden.textContent = "hidden content"; - root.append(basic, nested, container, contentHidden); + const inlineWhitespace = document.createElement("div"); + inlineWhitespace.append("alpha\n ", Object.assign(document.createElement("span"), { + textContent: "\n beta\n" + }), "\n gamma"); + root.append(basic, nested, container, contentHidden, inlineWhitespace); const scriptStyleRange = document.createRange(); scriptStyleRange.selectNode(p); const scriptStyle = selectedStringFor(scriptStyleRange).replace(/\r\n/g, "\n"); @@ -4492,7 +4496,8 @@ fn selection_to_string_uses_rendered_native_range_projection() { selectContents(basic), selectContents(nested), selectContents(container), - selectContents(contentHidden) + selectContents(contentHidden), + selectContents(inlineWhitespace) ].join("|"); })() "##, @@ -4501,7 +4506,7 @@ fn selection_to_string_uses_rendered_native_range_projection() { assert_eq!( result, - "\nstyle text line\nfunction x() { return 1; }\n\nPASS|Hell|ac|start end|selectabletext|" + "\nstyle text line\nfunction x() { return 1; }\n\nPASS|Hell|ac|start end|selectabletext||alpha beta gamma" ); }