Skip to content

Commit 5bdeb79

Browse files
authored
Merge pull request #20926 from calixteman/bug2022516
Correctly focus the pasted page (bug 2022516)
2 parents dabb2b9 + 4aee2e8 commit 5bdeb79

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
@@ -1271,6 +1271,68 @@ describe("Reorganize Pages View", () => {
12711271
})
12721272
);
12731273
});
1274+
1275+
it("should focus the newly pasted page after copy and paste (bug 2022516)", async () => {
1276+
await Promise.all(
1277+
pages.map(async ([browserName, page]) => {
1278+
await waitForThumbnailVisible(page, 1);
1279+
await page.waitForSelector("#viewsManagerStatusActionButton", {
1280+
visible: true,
1281+
});
1282+
1283+
// Select page 1 and copy it.
1284+
await waitAndClick(
1285+
page,
1286+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
1287+
);
1288+
let handlePagesEdited = await waitForPagesEdited(page, "copy");
1289+
await waitAndClick(page, "#viewsManagerStatusActionButton");
1290+
await waitAndClick(page, "#viewsManagerStatusActionCopy");
1291+
await awaitPromise(handlePagesEdited);
1292+
1293+
// Paste after page 3: the pasted page lands at position 4.
1294+
handlePagesEdited = await waitForPagesEdited(page);
1295+
await waitAndClick(page, `${getThumbnailSelector(3)}+button`);
1296+
await awaitPromise(handlePagesEdited);
1297+
1298+
// Focus must be on the newly pasted page (position 4), not page 1.
1299+
await page.waitForSelector(`${getThumbnailSelector(4)}:focus`, {
1300+
visible: true,
1301+
});
1302+
})
1303+
);
1304+
});
1305+
1306+
it("should focus the newly pasted page after cut and paste (bug 2022516)", async () => {
1307+
await Promise.all(
1308+
pages.map(async ([browserName, page]) => {
1309+
await waitForThumbnailVisible(page, 1);
1310+
await page.waitForSelector("#viewsManagerStatusActionButton", {
1311+
visible: true,
1312+
});
1313+
1314+
// Select page 3 and cut it.
1315+
await waitAndClick(
1316+
page,
1317+
`.thumbnail:has(${getThumbnailSelector(3)}) input`
1318+
);
1319+
let handlePagesEdited = await waitForPagesEdited(page, "cut");
1320+
await waitAndClick(page, "#viewsManagerStatusActionButton");
1321+
await waitAndClick(page, "#viewsManagerStatusActionCut");
1322+
await awaitPromise(handlePagesEdited);
1323+
1324+
// Paste after page 1: the pasted page lands at position 2.
1325+
handlePagesEdited = await waitForPagesEdited(page);
1326+
await waitAndClick(page, `${getThumbnailSelector(1)}+button`);
1327+
await awaitPromise(handlePagesEdited);
1328+
1329+
// Focus must be on the newly pasted page (position 2), not page 1.
1330+
await page.waitForSelector(`${getThumbnailSelector(2)}:focus`, {
1331+
visible: true,
1332+
});
1333+
})
1334+
);
1335+
});
12741336
});
12751337

12761338
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
@@ -730,13 +730,13 @@ class PDFThumbnailViewer {
730730
this.#selectedPages.clear();
731731
}
732732

733-
#updateCurrentPage(currentPageNumber) {
733+
#updateCurrentPage(currentPageNumber, forceFocus = false) {
734734
setTimeout(() => {
735735
this.forceRendering();
736736
const newPageNumber = currentPageNumber || 1;
737737
this.linkService.goToPage(newPageNumber);
738738
const thumbnailView = this._thumbnails[newPageNumber - 1];
739-
if (!this.container.contains(document.activeElement)) {
739+
if (forceFocus || !this.container.contains(document.activeElement)) {
740740
thumbnailView.imageContainer.focus();
741741
}
742742
}, 0);
@@ -898,7 +898,8 @@ class PDFThumbnailViewer {
898898
: this._currentPageNumber;
899899

900900
pagesMapper.pastePages(index);
901-
this.#updateCurrentPage(this.#updateThumbnails(currentPageNumber));
901+
this.#updateThumbnails(currentPageNumber);
902+
this.#updateCurrentPage(index + 1, /* forceFocus = */ true);
902903
this.#computeThumbnailsPosition();
903904

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

0 commit comments

Comments
 (0)