Skip to content

Commit fd87e66

Browse files
authored
Merge pull request #20047 from Aditi-1400/fix-horizontal-scroll
Make horizontal padding relative to device width
2 parents 426ee03 + c138887 commit fd87e66

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

test/integration/find_spec.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,32 @@ describe("find bar", () => {
149149
);
150150
});
151151
});
152+
153+
describe("scrolls to the search result text for smaller viewports", () => {
154+
let pages;
155+
156+
beforeEach(async () => {
157+
pages = await loadAndWait("tracemonkey.pdf", ".textLayer", 100);
158+
});
159+
160+
afterEach(async () => {
161+
await closePages(pages);
162+
});
163+
164+
it("must scroll to the search result text", async () => {
165+
await Promise.all(
166+
pages.map(async ([browserName, page]) => {
167+
// Set a smaller viewport to simulate a mobile device
168+
await page.setViewport({ width: 350, height: 600 });
169+
await page.click("#viewFindButton");
170+
await page.waitForSelector("#findInput", { visible: true });
171+
await page.type("#findInput", "productivity");
172+
173+
const highlight = await page.waitForSelector(".textLayer .highlight");
174+
175+
expect(await highlight.isIntersectingViewport()).toBeTrue();
176+
})
177+
);
178+
});
179+
});
152180
});

web/pdf_find_controller.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const FindState = {
2929

3030
const FIND_TIMEOUT = 250; // ms
3131
const MATCH_SCROLL_OFFSET_TOP = -50; // px
32-
const MATCH_SCROLL_OFFSET_LEFT = -400; // px
3332

3433
const CHARACTERS_TO_NORMALIZE = {
3534
"\u2010": "-", // Hyphen
@@ -573,10 +572,9 @@ class PDFFindController {
573572
return;
574573
}
575574
this._scrollMatches = false; // Ensure that scrolling only happens once.
576-
577575
const spot = {
578576
top: MATCH_SCROLL_OFFSET_TOP,
579-
left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT,
577+
left: selectedLeft,
580578
};
581579
scrollIntoView(element, spot, /* scrollMatches = */ true);
582580
}

web/ui_utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ function scrollIntoView(element, spot, scrollMatches = false) {
120120
offsetY += spot.top;
121121
}
122122
if (spot.left !== undefined) {
123-
offsetX += spot.left;
123+
const elementWidth = element.getBoundingClientRect().width;
124+
const padding = MathClamp(
125+
(parent.clientWidth - elementWidth) / 2,
126+
20,
127+
400
128+
);
129+
const left = spot.left - padding;
130+
offsetX += left;
124131
parent.scrollLeft = offsetX;
125132
}
126133
}

0 commit comments

Comments
 (0)