Revert "Make horizontal padding relative to device width"

This reverts commit c138887c1f7613bce44b99d22b63e2d744b0fb40.
This commit is contained in:
Calixte Denizet 2025-07-09 17:38:49 +02:00
parent 2dadac8877
commit e36f58ee4d
3 changed files with 4 additions and 37 deletions

View File

@ -149,32 +149,4 @@ describe("find bar", () => {
); );
}); });
}); });
describe("scrolls to the search result text for smaller viewports", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".textLayer", 100);
});
afterEach(async () => {
await closePages(pages);
});
it("must scroll to the search result text", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
// Set a smaller viewport to simulate a mobile device
await page.setViewport({ width: 350, height: 600 });
await page.click("#viewFindButton");
await page.waitForSelector("#findInput", { visible: true });
await page.type("#findInput", "productivity");
const highlight = await page.waitForSelector(".textLayer .highlight");
expect(await highlight.isIntersectingViewport()).toBeTrue();
})
);
});
});
}); });

View File

@ -29,6 +29,7 @@ const FindState = {
const FIND_TIMEOUT = 250; // ms const FIND_TIMEOUT = 250; // ms
const MATCH_SCROLL_OFFSET_TOP = -50; // px const MATCH_SCROLL_OFFSET_TOP = -50; // px
const MATCH_SCROLL_OFFSET_LEFT = -400; // px
const CHARACTERS_TO_NORMALIZE = { const CHARACTERS_TO_NORMALIZE = {
"\u2010": "-", // Hyphen "\u2010": "-", // Hyphen
@ -572,9 +573,10 @@ class PDFFindController {
return; return;
} }
this._scrollMatches = false; // Ensure that scrolling only happens once. this._scrollMatches = false; // Ensure that scrolling only happens once.
const spot = { const spot = {
top: MATCH_SCROLL_OFFSET_TOP, top: MATCH_SCROLL_OFFSET_TOP,
left: selectedLeft, left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT,
}; };
scrollIntoView(element, spot, /* scrollMatches = */ true); scrollIntoView(element, spot, /* scrollMatches = */ true);
} }

View File

@ -120,14 +120,7 @@ function scrollIntoView(element, spot, scrollMatches = false) {
offsetY += spot.top; offsetY += spot.top;
} }
if (spot.left !== undefined) { if (spot.left !== undefined) {
const elementWidth = element.getBoundingClientRect().width; offsetX += spot.left;
const padding = MathClamp(
(parent.clientWidth - elementWidth) / 2,
20,
400
);
const left = spot.left - padding;
offsetX += left;
parent.scrollLeft = offsetX; parent.scrollLeft = offsetX;
} }
} }