mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:48:12 +00:00
LibHTML: Clicking on a fragment link should prefer <a id> over <a name>
It turns out that other engines prefer <a id> over <a name> when deciding which anchor element to jump to. This patch aligns LibHTML's behavior with WebKit and Gecko. Thanks to "/cam 2" for bringing this up. :^)
This commit is contained in:
parent
4d9740ecef
commit
8e710b16de
1 changed files with 12 additions and 9 deletions
|
@ -319,17 +319,20 @@ void HtmlView::scroll_to_anchor(const StringView& name)
|
||||||
if (!document())
|
if (!document())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HTMLAnchorElement* element = nullptr;
|
const HTMLAnchorElement* element = nullptr;
|
||||||
document()->for_each_in_subtree([&](auto& node) {
|
if (auto* candidate = document()->get_element_by_id(name)) {
|
||||||
if (is<HTMLAnchorElement>(node)) {
|
if (is<HTMLAnchorElement>(*candidate))
|
||||||
auto& anchor_element = to<HTMLAnchorElement>(node);
|
element = to<HTMLAnchorElement>(candidate);
|
||||||
if (anchor_element.name() == name) {
|
}
|
||||||
element = &anchor_element;
|
if (!element) {
|
||||||
return IterationDecision::Break;
|
auto candidates = document()->get_elements_by_name(name);
|
||||||
|
for (auto* candidate : candidates) {
|
||||||
|
if (is<HTMLAnchorElement>(*candidate)) {
|
||||||
|
element = to<HTMLAnchorElement>(candidate);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (!element) {
|
if (!element) {
|
||||||
dbg() << "HtmlView::scroll_to_anchor(): Anchor not found: '" << name << "'";
|
dbg() << "HtmlView::scroll_to_anchor(): Anchor not found: '" << name << "'";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue