Skip to content

Commit f98ce9c

Browse files
committed
Avoid to have multiple selected pages after copy/cut operations (bug 2026639)
1 parent 466c626 commit f98ce9c

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

test/integration/reorganize_pages_spec.mjs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,4 +2908,83 @@ describe("Reorganize Pages View", () => {
29082908
);
29092909
});
29102910
});
2911+
2912+
describe("Current page indicator (bug 2026639)", () => {
2913+
let pages;
2914+
2915+
beforeEach(async () => {
2916+
pages = await loadAndWait(
2917+
"page_with_number.pdf",
2918+
"#viewsManagerToggleButton",
2919+
"page-fit",
2920+
null,
2921+
{ enableSplitMerge: true }
2922+
);
2923+
});
2924+
2925+
afterEach(async () => {
2926+
await closePages(pages);
2927+
});
2928+
2929+
it("should have only one current page after repeated cut/undo operations", async () => {
2930+
await Promise.all(
2931+
pages.map(async ([browserName, page]) => {
2932+
await waitForThumbnailVisible(page, 1);
2933+
await page.waitForSelector("#viewsManagerStatusActionButton", {
2934+
visible: true,
2935+
});
2936+
2937+
const countCurrentThumbnails = () =>
2938+
page.evaluate(
2939+
() =>
2940+
document.querySelectorAll(
2941+
'.thumbnailImageContainer[aria-current="page"]'
2942+
).length
2943+
);
2944+
2945+
// Copy page 1 and paste it after page 3.
2946+
await waitAndClick(
2947+
page,
2948+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
2949+
);
2950+
let handlePagesEdited = await waitForPagesEdited(page, "copy");
2951+
await waitAndClick(page, "#viewsManagerStatusActionButton");
2952+
await waitAndClick(page, "#viewsManagerStatusActionCopy");
2953+
await awaitPromise(handlePagesEdited);
2954+
2955+
handlePagesEdited = await waitForPagesEdited(page);
2956+
await waitAndClick(page, `${getThumbnailSelector(3)}+button`);
2957+
await awaitPromise(handlePagesEdited);
2958+
2959+
// Repeat cut/undo three times and check the current indicator each
2960+
// time.
2961+
for (let i = 0; i < 3; i++) {
2962+
await waitAndClick(
2963+
page,
2964+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
2965+
);
2966+
handlePagesEdited = await waitForPagesEdited(page, "cut");
2967+
await waitAndClick(page, "#viewsManagerStatusActionButton");
2968+
await waitAndClick(page, "#viewsManagerStatusActionCut");
2969+
await awaitPromise(handlePagesEdited);
2970+
2971+
expect(await countCurrentThumbnails())
2972+
.withContext(`In ${browserName}, after cut #${i + 1}`)
2973+
.toBe(1);
2974+
2975+
await page.waitForSelector("#viewsManagerStatusUndo", {
2976+
visible: true,
2977+
});
2978+
handlePagesEdited = await waitForPagesEdited(page, "cancelDelete");
2979+
await waitAndClick(page, "#viewsManagerStatusUndoButton");
2980+
await awaitPromise(handlePagesEdited);
2981+
2982+
expect(await countCurrentThumbnails())
2983+
.withContext(`In ${browserName}, after undo #${i + 1}`)
2984+
.toBe(1);
2985+
}
2986+
})
2987+
);
2988+
});
2989+
});
29112990
});

web/pdf_thumbnail_viewer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,13 @@ class PDFThumbnailViewer {
766766

767767
this.#isCut = false;
768768
if (this.#savedThumbnails) {
769+
// The thumbnail objects are shared between the post-operation list and
770+
// the saved (pre-operation) list. The object marked current in the
771+
// post-operation list may reappear at a different index in the restored
772+
// list.
773+
const currentThumb = this._thumbnails[this._currentPageNumber - 1];
774+
currentThumb?.toggleCurrent(false);
775+
769776
const fragment = document.createDocumentFragment();
770777
for (let i = 1, ii = this.#savedThumbnails.length; i <= ii; i++) {
771778
const thumbnail = this.#savedThumbnails[i - 1];
@@ -776,6 +783,13 @@ class PDFThumbnailViewer {
776783
this.container.replaceChildren(fragment);
777784
this._thumbnails = this.#savedThumbnails;
778785
this.#savedThumbnails = null;
786+
787+
// Re-establish the current-page indicator at the position the current
788+
// thumbnail now occupies in the restored list.
789+
const newIdx = currentThumb ? this._thumbnails.indexOf(currentThumb) : -1;
790+
this._currentPageNumber = newIdx + 1;
791+
currentThumb?.toggleCurrent(newIdx !== -1);
792+
779793
this.#pagesMapper.cancelDelete();
780794

781795
this.eventBus.dispatch("pagesedited", {

0 commit comments

Comments
 (0)