From 645ef0876408abefdc4b9ada163599f981fd3fa2 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 9 Mar 2026 19:10:12 +0100 Subject: [PATCH] Avoid to have a thumbnail with two paste buttons (bug 2021886) --- test/integration/reorganize_pages_spec.mjs | 46 ++++++++++++++++++++++ web/pdf_thumbnail_viewer.js | 6 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/test/integration/reorganize_pages_spec.mjs b/test/integration/reorganize_pages_spec.mjs index 389a69f3602c5..5ba0f0b2d4c7a 100644 --- a/test/integration/reorganize_pages_spec.mjs +++ b/test/integration/reorganize_pages_spec.mjs @@ -922,6 +922,52 @@ describe("Reorganize Pages View", () => { }) ); }); + + it("should have only one paste button next to the second thumbnail after cut, paste, and copy", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForThumbnailVisible(page, 1); + await page.waitForSelector("#viewsManagerStatusActionButton", { + visible: true, + }); + + // Select page 1 and cut it. + await waitAndClick( + page, + `.thumbnail:has(${getThumbnailSelector(1)}) input` + ); + let handlePagesEdited = await waitForPagesEdited(page, "cut"); + await waitAndClick(page, "#viewsManagerStatusActionButton"); + await waitAndClick(page, "#viewsManagerStatusActionCut"); + await awaitPromise(handlePagesEdited); + + // Paste after the new first thumbnail (originally page 2). + handlePagesEdited = await waitForPagesEdited(page); + await waitAndClick(page, `${getThumbnailSelector(1)}+button`); + await awaitPromise(handlePagesEdited); + + // Select the new first thumbnail and copy it. + handlePagesEdited = await waitForPagesEdited(page); + await waitAndClick( + page, + `.thumbnail:has(${getThumbnailSelector(1)}) input` + ); + await waitAndClick(page, "#viewsManagerStatusActionButton"); + await waitAndClick(page, "#viewsManagerStatusActionCopy"); + await awaitPromise(handlePagesEdited); + + // The second thumbnail should have only one paste button after it. + await page.waitForSelector( + `${getThumbnailSelector(2)} + button.thumbnailPasteButton`, + { visible: true } + ); + const pasteButtons = await page.$$( + `${getThumbnailSelector(2)} + button.thumbnailPasteButton` + ); + expect(pasteButtons.length).withContext(`In ${browserName}`).toBe(1); + }) + ); + }); }); describe("Keyboard shortcuts for cut and copy (bug 2018139)", () => { diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js index 8ee1cb29473f4..2085791b49d34 100644 --- a/web/pdf_thumbnail_viewer.js +++ b/web/pdf_thumbnail_viewer.js @@ -818,9 +818,6 @@ class PDFThumbnailViewer { } #pastePages(index) { - this.#togglePasteMode(false); - this.#toggleMenuEntries(true); - const pagesMapper = this.#pagesMapper; let currentPageNumber = this.#copiedPageNumbers.includes( this._currentPageNumber @@ -840,7 +837,8 @@ class PDFThumbnailViewer { this.#copiedThumbnails = null; this.#isCut = false; - this.#updateMenuEntries(); + this.#togglePasteMode(false); + this.#toggleMenuEntries(false); this.#updateStatus("select"); this.#updateCurrentPage(currentPageNumber);