mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 13:20:59 +00:00 
			
		
		
		
	LibWeb: Do not rely on the layout tree for collapsed line breaks
The editing command that relies the most on this, `insertLinebreak`, did not perform a layout update after inserting a `<br>` which caused this algorithm to always return false. But instead of actually building the layout tree needlessly, we can check the DOM tree instead.
This commit is contained in:
		
							parent
							
								
									71a4e18bf8
								
							
						
					
					
						commit
						295b78f7d3
					
				
				
				Notes:
				
					github-actions[bot]
				
				2025-05-01 12:45:22 +00:00 
				
			
			Author: https://github.com/gmta
Commit: 295b78f7d3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4542
			
					 3 changed files with 17 additions and 9 deletions
				
			
		|  | @ -1981,15 +1981,10 @@ bool is_collapsed_line_break(GC::Ref<DOM::Node> node) | |||
|         return false; | ||||
| 
 | ||||
|     // that begins a line box which has nothing else in it, and therefore has zero height.
 | ||||
|     auto layout_node = node->layout_node(); | ||||
|     if (!layout_node) | ||||
|         return false; | ||||
|     VERIFY(is<Layout::BreakNode>(*layout_node)); | ||||
| 
 | ||||
|     // NOTE: We do not generate a TextNode for empty text after the break, so if we do not have a sibling or if that
 | ||||
|     //       sibling is not a TextNode, we consider it a collapsed line break.
 | ||||
|     auto* next_layout_node = layout_node->next_sibling(); | ||||
|     return !is<Layout::TextNode>(next_layout_node); | ||||
|     // NOTE: We check this on the DOM-level by seeing if the next node is neither a non-empty text node nor a <br>.
 | ||||
|     if (auto text_node = as_if<DOM::Text>(node->next_sibling())) | ||||
|         return text_node->text_content().value_or({}).is_empty(); | ||||
|     return !is<HTML::HTMLBRElement>(node->next_sibling()); | ||||
| } | ||||
| 
 | ||||
| // https://w3c.github.io/editing/docs/execCommand/#collapsed-whitespace-node
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jelle Raaijmakers
						Jelle Raaijmakers