From f6f80a1a72b25d6062462b1667e7e0b8287635fc Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 18 Dec 2023 21:31:31 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index c3d2b1627e..efbee2cc28 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/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)