Skip to content

Commit 0128ead

Browse files
authored
Merge pull request #20985 from calixteman/bug2023150_2
Avoid to be blocked when searching after a page move (bug 2023150)
2 parents 4751311 + 2d43ba2 commit 0128ead

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

test/integration/reorganize_pages_spec.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,49 @@ describe("Reorganize Pages View", () => {
450450
);
451451
});
452452

453+
it("should check that find navigation is not blocked after moving pages (bug 2023150)", async () => {
454+
await Promise.all(
455+
pages.map(async ([browserName, page]) => {
456+
await waitAndClick(page, "#viewFindButton");
457+
await page.waitForSelector("#findInput", { visible: true });
458+
await page.type("#findInput", "1");
459+
await page.keyboard.press("Enter");
460+
461+
// Wait for the first result to be selected and the search to settle.
462+
await page.waitForSelector("#findInput[data-status='']");
463+
let resultEl = await page.waitForSelector("#findResultsCount");
464+
const firstResult = await resultEl.evaluate(el => el.textContent);
465+
expect(firstResult)
466+
.withContext(`In ${browserName}`)
467+
.toEqual(`${FSI}1${PDI} of ${FSI}10${PDI} matches`);
468+
469+
// Navigate to the next match.
470+
await page.keyboard.press("Enter");
471+
await page.waitForSelector("#findInput[data-status='']");
472+
resultEl = await page.waitForSelector("#findResultsCount");
473+
const secondResult = await resultEl.evaluate(el => el.textContent);
474+
expect(secondResult)
475+
.withContext(`In ${browserName}`)
476+
.toEqual(`${FSI}2${PDI} of ${FSI}10${PDI} matches`);
477+
478+
// Move a page: this previously blocked subsequent find navigation.
479+
await movePages(page, [3], 0);
480+
481+
// Wait for the search to re-run after the page move.
482+
await page.waitForSelector("#findInput[data-status='']");
483+
484+
// Navigate to the next match — must not be blocked.
485+
await page.keyboard.press("Enter");
486+
await page.waitForSelector("#findInput[data-status='']");
487+
resultEl = await page.waitForSelector("#findResultsCount");
488+
const resultAfterMove = await resultEl.evaluate(el => el.textContent);
489+
expect(resultAfterMove)
490+
.withContext(`In ${browserName}`)
491+
.not.toEqual(secondResult);
492+
})
493+
);
494+
});
495+
453496
it("should check if the search is working after copy and paste (bug 2023150)", async () => {
454497
await Promise.all(
455498
pages.map(async ([browserName, page]) => {

web/pdf_find_controller.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,14 @@ class PDFFindController {
11681168
return;
11691169
}
11701170

1171-
this.#onFindBarClose();
1171+
// Cancel any pending find timeout and clear a pending resume page index
1172+
// synchronously. Calling #onFindBarClose() here would schedule its cleanup
1173+
// asynchronously.
1174+
if (this._findTimeout) {
1175+
clearTimeout(this._findTimeout);
1176+
this._findTimeout = null;
1177+
}
1178+
this._resumePageIdx = null;
11721179
this._dirtyMatch = true;
11731180
const prevPromises = this._extractTextPromises;
11741181
const prevContents = this._pageContents;
@@ -1198,11 +1205,7 @@ class PDFFindController {
11981205
hasDiacritics.push(prevDiacritics[prevPageNumber - 1] ?? false);
11991206
}
12001207
if (this.#state) {
1201-
this._eventBus.dispatch("find", {
1202-
source: this,
1203-
type: "",
1204-
...this.#state,
1205-
});
1208+
this.#nextMatch();
12061209
}
12071210
}
12081211

0 commit comments

Comments
 (0)