mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	LibWebView: Scroll inspected elements into view with a slight offset
When scrolling to the inspected element, if we scroll to its exact position, it would often be placed behind the fixed header at the top of the WebView. This patch gives the scroll a bit of an offset to scroll comfortably beneath the header.
This commit is contained in:
		
							parent
							
								
									aa4dcda5dc
								
							
						
					
					
						commit
						7cdd07b89a
					
				
					 1 changed files with 11 additions and 1 deletions
				
			
		|  | @ -322,6 +322,16 @@ void InspectorClient::maybe_load_inspector() | ||||||
|         let initialTabButton = document.getElementById("dom-tree-button"); |         let initialTabButton = document.getElementById("dom-tree-button"); | ||||||
|         selectTab(initialTabButton, "dom-tree"); |         selectTab(initialTabButton, "dom-tree"); | ||||||
| 
 | 
 | ||||||
|  |         const scrollToElement = (element) => { | ||||||
|  |             // Include an offset to prevent the element being placed behind the fixed `tab-controls` header.
 | ||||||
|  |             const offset = 45; | ||||||
|  | 
 | ||||||
|  |             let position = element.getBoundingClientRect().top; | ||||||
|  |             position += window.pageYOffset - offset; | ||||||
|  | 
 | ||||||
|  |             window.scrollTo(0, position); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         inspector.inspectDOMNodeID = nodeID => { |         inspector.inspectDOMNodeID = nodeID => { | ||||||
|             let domNodes = document.querySelectorAll(`[data-id="${nodeID}"]`); |             let domNodes = document.querySelectorAll(`[data-id="${nodeID}"]`); | ||||||
|             if (domNodes.length !== 1) { |             if (domNodes.length !== 1) { | ||||||
|  | @ -335,7 +345,7 @@ void InspectorClient::maybe_load_inspector() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             inspectDOMNode(domNodes[0]); |             inspectDOMNode(domNodes[0]); | ||||||
|             selectedDOMNode.scrollIntoView({ block: "start", inline: "start" }); |             scrollToElement(selectedDOMNode); | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         inspector.clearInspectedDOMNode = () => { |         inspector.clearInspectedDOMNode = () => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn