Merge pull request #21138 from calixteman/bug2034111

Fix status label mismatch after merging with a pre-existing selection (bug 2034111)
This commit is contained in:
Tim van der Meij 2026-04-24 20:07:50 +02:00 committed by GitHub
commit 7dc4812643
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View File

@ -3123,5 +3123,50 @@ describe("Reorganize Pages View", () => {
})
);
});
it("should show only merged pages as selected when a page was pre-selected (bug 2034111)", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await waitForThumbnailVisible(page, 1);
const labelSelector = "#viewsManagerStatusActionLabel";
// Select page 1 before merging.
await waitAndClick(
page,
`.thumbnail:has(${getThumbnailSelector(1)}) input`
);
await waitForTextToBe(page, labelSelector, `${FSI}1${PDI} selected`);
const handleMerged = await createPromise(page, resolve => {
window.PDFViewerApplication.eventBus._on(
"thumbnailsloaded",
resolve,
{ once: true }
);
});
const picker = await page.$("#viewsManagerAddFilePicker");
await picker.uploadFile(
path.join(__dirname, "../pdfs/three_pages_with_number.pdf")
);
await awaitPromise(handleMerged);
// Original 3 pages + 3 merged pages = 6 pages total.
await page.waitForFunction(
() => parseInt(document.getElementById("pageNumber").max, 10) === 6
);
// Label must show exactly the 3 newly inserted pages — the
// pre-merge selection of page 1 must have been cleared.
await waitForTextToBe(page, labelSelector, `${FSI}3${PDI} selected`);
// Focus must move to the first newly inserted page (page 2).
await page.waitForFunction(
() => window.PDFViewerApplication.page === 2
);
})
);
});
});
});

View File

@ -339,6 +339,11 @@ class PDFThumbnailViewer {
this.eventBus._on(
"thumbnailsloaded",
() => {
// Clear any pre-merge selection: thumbnails are rebuilt fresh
// (all unchecked), so the old set would cause a label/visual
// mismatch.
this.#selectedPages = null;
this.#updateMenuEntries();
this.#toggleBar("status");
const newPagesCount = this.#pagesMapper.pagesNumber;
const insertedPagesCount = newPagesCount - pagesCount;
@ -351,6 +356,9 @@ class PDFThumbnailViewer {
this._thumbnails[i].checkbox.checked = true;
this.#selectPage(i + 1, true);
}
if (insertedPagesCount) {
this.#updateCurrentPage(currentPageIndex + 2);
}
},
{ once: true }
);