Merge pull request #13482 from Snuffleupagus/scrollMatches-fix

Fix scrolling of search results in documents with marked content (bug 1714183)
This commit is contained in:
Brendan Dahl 2021-06-04 10:16:05 -07:00 committed by GitHub
commit 425e58431a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -223,7 +223,7 @@ class PDFFindController {
top: MATCH_SCROLL_OFFSET_TOP,
left: MATCH_SCROLL_OFFSET_LEFT,
};
scrollIntoView(element, spot, /* skipOverflowHiddenElements = */ true);
scrollIntoView(element, spot, /* scrollMatches = */ true);
}
_reset() {

View File

@ -97,10 +97,11 @@ function getOutputScale(ctx) {
* @param {Object} element - The element to be visible.
* @param {Object} spot - An object with optional top and left properties,
* specifying the offset from the top left edge.
* @param {boolean} skipOverflowHiddenElements - Ignore elements that have
* the CSS rule `overflow: hidden;` set. The default is false.
* @param {boolean} [scrollMatches] - When scrolling search results into view,
* ignore elements that either: Contains marked content identifiers,
* or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
*/
function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
function scrollIntoView(element, spot, scrollMatches = false) {
// Assuming offsetParent is available (it's not available when viewer is in
// hidden iframe or object). We have to scroll: if the offsetParent is not set
// producing the error. See also animationStarted.
@ -114,15 +115,13 @@ function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
while (
(parent.clientHeight === parent.scrollHeight &&
parent.clientWidth === parent.scrollWidth) ||
(skipOverflowHiddenElements &&
getComputedStyle(parent).overflow === "hidden")
(scrollMatches &&
(parent.classList.contains("markedContent") ||
getComputedStyle(parent).overflow === "hidden"))
) {
if (parent.dataset._scaleY) {
offsetY /= parent.dataset._scaleY;
offsetX /= parent.dataset._scaleX;
}
offsetY += parent.offsetTop;
offsetX += parent.offsetLeft;
parent = parent.offsetParent;
if (!parent) {
return; // no need to scroll