Skip to content

Truly independent web browser

LibWeb: Find the empty first line of text that starts with a newline

Andreas Kling169d2f75a33a
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_lines.rs b/Libraries/LibWeb/Rust/src/painting/visual_lines.rs
index a3447339719..401f306e130 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_lines.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_lines.rs
@@ -43,6 +43,16 @@ fn for_each_empty_visual_line_position(
segments.push((node, &content.text));
}
}
+ // A text that starts with a newline starts with an empty line.
+ if let Some(&(node, text)) = segments.first()
+ && text.first() == Some(&u16::from(b'\n'))
+ {
+ let dom_offset =
+ layout_arena.dom_offset_for_rendered_text_offset(node, 0, crate::layout::RenderedTextBoundary::Start);
+ if !callback(dom_offset) {
+ return;
+ }
+ }
for (segment_index, &(node, text)) in segments.iter().enumerate() {
for (rendered_offset, code_unit) in text.iter().enumerate() {
if *code_unit != u16::from(b'\n') {
diff --git a/Tests/LibWeb/Text/expected/textarea-empty-line-caret.txt b/Tests/LibWeb/Text/expected/textarea-empty-line-caret.txt
index 2b6cee3a03e..484c28ab4b9 100644
--- a/Tests/LibWeb/Text/expected/textarea-empty-line-caret.txt
+++ b/Tests/LibWeb/Text/expected/textarea-empty-line-caret.txt
@@ -3,4 +3,4 @@ a trailing newline adds a line with white-space: pre-line: false
typed: caret on the empty last line is visible: true
execCommand: caret on the empty last line is visible: false
caret moved onto an empty middle line is visible: false
-caret on an empty first line is painted: false
+caret on an empty first line is painted: true