Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions test/integration/find_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
);
});
});
});
4 changes: 3 additions & 1 deletion web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const FindState = {

const FIND_TIMEOUT = 250; // ms
const MATCH_SCROLL_OFFSET_TOP = -50; // px
const MATCH_SCROLL_OFFSET_LEFT = -400; // px

const CHARACTERS_TO_NORMALIZE = {
"\u2010": "-", // Hyphen
Expand Down Expand Up @@ -572,9 +573,10 @@ class PDFFindController {
return;
}
this._scrollMatches = false; // Ensure that scrolling only happens once.

const spot = {
top: MATCH_SCROLL_OFFSET_TOP,
left: selectedLeft,
left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT,
};
scrollIntoView(element, spot, /* scrollMatches = */ true);
}
Expand Down
9 changes: 1 addition & 8 deletions web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,7 @@ function scrollIntoView(element, spot, scrollMatches = false) {
offsetY += spot.top;
}
if (spot.left !== undefined) {
const elementWidth = element.getBoundingClientRect().width;
const padding = MathClamp(
(parent.clientWidth - elementWidth) / 2,
20,
400
);
const left = spot.left - padding;
offsetX += left;
offsetX += spot.left;
parent.scrollLeft = offsetX;
}
}
Expand Down