瀏覽代碼

LibWeb: Scroll to "nearest" instead of "start" in set_focused_element()

Fixes a bug when after clicking on a button/click the page is scrolled
to start of the element.
Aliaksandr Kalenik 1 年之前
父節點
當前提交
f6f80a1a72
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 6 - 2
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -1700,8 +1700,12 @@ void Document::set_focused_element(Element* element)
         m_layout_root->set_needs_display();
 
     // Scroll the viewport if necessary to make the newly focused element visible.
-    if (m_focused_element)
-        (void)m_focused_element->scroll_into_view();
+    if (m_focused_element) {
+        ScrollIntoViewOptions scroll_options;
+        scroll_options.block = Bindings::ScrollLogicalPosition::Nearest;
+        scroll_options.inline_ = Bindings::ScrollLogicalPosition::Nearest;
+        (void)m_focused_element->scroll_into_view(scroll_options);
+    }
 }
 
 void Document::set_active_element(Element* element)