Skip to content

Commit

Permalink
Bug 1906895 - Text Fragments: Scroll the start container of a range i…
Browse files Browse the repository at this point in the history
…nto view instead of its common ancestor. r=emilio

Spec issue: WICG/scroll-to-text-fragment#259

Differential Revision: https://phabricator.services.mozilla.com/D216147
  • Loading branch information
jnjaeschke committed Jul 15, 2024
1 parent ea8282e commit 620fb78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3093,11 +3093,16 @@ nsresult PresShell::GoToAnchor(const nsAString& aAnchorName,
// end node.
// 3.4.2 While target is non-null and is not an element, set target to
// target's parent.
// ------
// Common closest ancestor is not suitable here, as it can scroll to positions
// where no text directive is visible. Instead, scroll to the start container
// of the text directive.
// see https://bugzil.la/1906895 and
// https://github.com/WICG/scroll-to-text-fragment/issues/259
Element* textFragmentTargetElement = [&aFirstTextDirective]() -> Element* {
nsINode* node =
aFirstTextDirective
? aFirstTextDirective->GetClosestCommonInclusiveAncestor()
: nullptr;
nsINode* node = aFirstTextDirective
? aFirstTextDirective->GetStartContainer()
: nullptr;
while (node && !node->IsElement()) {
node = node->GetParent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
fragment: '#:~:text=horizontally%20scrolled%20text',
expect_position: 'horizontal-scroll',
description: 'Text directive should horizontally scroll into view'
},
{
fragment: '#:~:text=Element,This',
expect_position: 'element',
description: 'Text directive that spans a range larger than the viewport should scroll the start into view'
}
];

Expand Down

0 comments on commit 620fb78

Please sign in to comment.