소스 검색

Browser: An anchor link should open in a new tab when required

Previously, clicking on an anchor link (href="#section1")
would always scroll to it on the current page, even if control was
held or the target="_blank" attribute was set. This fixes that
behaviour, and the link will always open in a new tab if required.
FalseHonesty 5 년 전
부모
커밋
78412ee76d
1개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 9 7
      Applications/Browser/Tab.cpp

+ 9 - 7
Applications/Browser/Tab.cpp

@@ -146,15 +146,17 @@ Tab::Tab()
     };
     };
 
 
     m_html_widget->on_link_click = [this](auto& href, auto& target, unsigned modifiers) {
     m_html_widget->on_link_click = [this](auto& href, auto& target, unsigned modifiers) {
-        if (href.starts_with("#")) {
-            auto anchor = href.substring_view(1, href.length() - 1);
-            m_html_widget->scroll_to_anchor(anchor);
-        } else {
+        if (target == "_blank" || modifiers == Mod_Ctrl) {
             auto url = m_html_widget->document()->complete_url(href);
             auto url = m_html_widget->document()->complete_url(href);
-            if (target == "_blank" || modifiers == Mod_Ctrl)
-                on_tab_open_request(url);
-            else
+            on_tab_open_request(url);
+        } else {
+            if (href.starts_with("#")) {
+                auto anchor = href.substring_view(1, href.length() - 1);
+                m_html_widget->scroll_to_anchor(anchor);
+            } else {
+                auto url = m_html_widget->document()->complete_url(href);
                 m_html_widget->load(url);
                 m_html_widget->load(url);
+            }
         }
         }
     };
     };