Skip to content

Commit 4aee2e8

Browse files
committed
Correctly focus the pasted page (bug 2022516)
1 parent ff1af5a commit 4aee2e8

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

test/integration/reorganize_pages_spec.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,68 @@ describe("Reorganize Pages View", () => {
12671267
})
12681268
);
12691269
});
1270+
1271+
it("should focus the newly pasted page after copy and paste (bug 2022516)", async () => {
1272+
await Promise.all(
1273+
pages.map(async ([browserName, page]) => {
1274+
await waitForThumbnailVisible(page, 1);
1275+
await page.waitForSelector("#viewsManagerStatusActionButton", {
1276+
visible: true,
1277+
});
1278+
1279+
// Select page 1 and copy it.
1280+
await waitAndClick(
1281+
page,
1282+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
1283+
);
1284+
let handlePagesEdited = await waitForPagesEdited(page, "copy");
1285+
await waitAndClick(page, "#viewsManagerStatusActionButton");
1286+
await waitAndClick(page, "#viewsManagerStatusActionCopy");
1287+
await awaitPromise(handlePagesEdited);
1288+
1289+
// Paste after page 3: the pasted page lands at position 4.
1290+
handlePagesEdited = await waitForPagesEdited(page);
1291+
await waitAndClick(page, `${getThumbnailSelector(3)}+button`);
1292+
await awaitPromise(handlePagesEdited);
1293+
1294+
// Focus must be on the newly pasted page (position 4), not page 1.
1295+
await page.waitForSelector(`${getThumbnailSelector(4)}:focus`, {
1296+
visible: true,
1297+
});
1298+
})
1299+
);
1300+
});
1301+
1302+
it("should focus the newly pasted page after cut and paste (bug 2022516)", async () => {
1303+
await Promise.all(
1304+
pages.map(async ([browserName, page]) => {
1305+
await waitForThumbnailVisible(page, 1);
1306+
await page.waitForSelector("#viewsManagerStatusActionButton", {
1307+
visible: true,
1308+
});
1309+
1310+
// Select page 3 and cut it.
1311+
await waitAndClick(
1312+
page,
1313+
`.thumbnail:has(${getThumbnailSelector(3)}) input`
1314+
);
1315+
let handlePagesEdited = await waitForPagesEdited(page, "cut");
1316+
await waitAndClick(page, "#viewsManagerStatusActionButton");
1317+
await waitAndClick(page, "#viewsManagerStatusActionCut");
1318+
await awaitPromise(handlePagesEdited);
1319+
1320+
// Paste after page 1: the pasted page lands at position 2.
1321+
handlePagesEdited = await waitForPagesEdited(page);
1322+
await waitAndClick(page, `${getThumbnailSelector(1)}+button`);
1323+
await awaitPromise(handlePagesEdited);
1324+
1325+
// Focus must be on the newly pasted page (position 2), not page 1.
1326+
await page.waitForSelector(`${getThumbnailSelector(2)}:focus`, {
1327+
visible: true,
1328+
});
1329+
})
1330+
);
1331+
});
12701332
});
12711333

12721334
describe("Status label reflects number of checked thumbnails (bug 2010832)", () => {

web/pdf_thumbnail_viewer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,13 @@ class PDFThumbnailViewer {
729729
this.#selectedPages.clear();
730730
}
731731

732-
#updateCurrentPage(currentPageNumber) {
732+
#updateCurrentPage(currentPageNumber, forceFocus = false) {
733733
setTimeout(() => {
734734
this.forceRendering();
735735
const newPageNumber = currentPageNumber || 1;
736736
this.linkService.goToPage(newPageNumber);
737737
const thumbnailView = this._thumbnails[newPageNumber - 1];
738-
if (!this.container.contains(document.activeElement)) {
738+
if (forceFocus || !this.container.contains(document.activeElement)) {
739739
thumbnailView.imageContainer.focus();
740740
}
741741
}, 0);
@@ -883,7 +883,8 @@ class PDFThumbnailViewer {
883883
: this._currentPageNumber;
884884

885885
pagesMapper.pastePages(index);
886-
this.#updateCurrentPage(this.#updateThumbnails(currentPageNumber));
886+
this.#updateThumbnails(currentPageNumber);
887+
this.#updateCurrentPage(index + 1, /* forceFocus = */ true);
887888
this.#computeThumbnailsPosition();
888889

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

0 commit comments

Comments
 (0)