Merge pull request #13600 from Snuffleupagus/scrollMatchIntoView-selectedLeft
Take the position of the `selected` element into account when scrolling matches (issue 13596)
This commit is contained in:
commit
82660296d6
@ -210,7 +210,12 @@ class PDFFindController {
|
||||
});
|
||||
}
|
||||
|
||||
scrollMatchIntoView({ element = null, pageIndex = -1, matchIndex = -1 }) {
|
||||
scrollMatchIntoView({
|
||||
element = null,
|
||||
selectedLeft = 0,
|
||||
pageIndex = -1,
|
||||
matchIndex = -1,
|
||||
}) {
|
||||
if (!this._scrollMatches || !element) {
|
||||
return;
|
||||
} else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
|
||||
@ -222,7 +227,7 @@ class PDFFindController {
|
||||
|
||||
const spot = {
|
||||
top: MATCH_SCROLL_OFFSET_TOP,
|
||||
left: MATCH_SCROLL_OFFSET_LEFT,
|
||||
left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT,
|
||||
};
|
||||
scrollIntoView(element, spot, /* scrollMatches = */ true);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ class TextLayerBuilder {
|
||||
function beginText(begin, className) {
|
||||
const divIdx = begin.divIdx;
|
||||
textDivs[divIdx].textContent = "";
|
||||
appendTextToDiv(divIdx, 0, begin.offset, className);
|
||||
return appendTextToDiv(divIdx, 0, begin.offset, className);
|
||||
}
|
||||
|
||||
function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
|
||||
@ -242,9 +242,10 @@ class TextLayerBuilder {
|
||||
span.className = `${className} appended`;
|
||||
span.appendChild(node);
|
||||
div.appendChild(span);
|
||||
return;
|
||||
return className.includes("selected") ? span.offsetLeft : 0;
|
||||
}
|
||||
div.appendChild(node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let i0 = selectedMatchIdx,
|
||||
@ -263,15 +264,7 @@ class TextLayerBuilder {
|
||||
const end = match.end;
|
||||
const isSelected = isSelectedPage && i === selectedMatchIdx;
|
||||
const highlightSuffix = isSelected ? " selected" : "";
|
||||
|
||||
if (isSelected) {
|
||||
// Attempt to scroll the selected match into view.
|
||||
findController.scrollMatchIntoView({
|
||||
element: textDivs[begin.divIdx],
|
||||
pageIndex: pageIdx,
|
||||
matchIndex: selectedMatchIdx,
|
||||
});
|
||||
}
|
||||
let selectedLeft = 0;
|
||||
|
||||
// Match inside new div.
|
||||
if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
|
||||
@ -286,14 +279,14 @@ class TextLayerBuilder {
|
||||
}
|
||||
|
||||
if (begin.divIdx === end.divIdx) {
|
||||
appendTextToDiv(
|
||||
selectedLeft = appendTextToDiv(
|
||||
begin.divIdx,
|
||||
begin.offset,
|
||||
end.offset,
|
||||
"highlight" + highlightSuffix
|
||||
);
|
||||
} else {
|
||||
appendTextToDiv(
|
||||
selectedLeft = appendTextToDiv(
|
||||
begin.divIdx,
|
||||
begin.offset,
|
||||
infinity.offset,
|
||||
@ -305,6 +298,16 @@ class TextLayerBuilder {
|
||||
beginText(end, "highlight end" + highlightSuffix);
|
||||
}
|
||||
prevEnd = end;
|
||||
|
||||
if (isSelected) {
|
||||
// Attempt to scroll the selected match into view.
|
||||
findController.scrollMatchIntoView({
|
||||
element: textDivs[begin.divIdx],
|
||||
selectedLeft,
|
||||
pageIndex: pageIdx,
|
||||
matchIndex: selectedMatchIdx,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (prevEnd) {
|
||||
|
Loading…
Reference in New Issue
Block a user