diff --git a/test/integration/reorganize_pages_spec.mjs b/test/integration/reorganize_pages_spec.mjs index 95c7de93c..6b05f9f3e 100644 --- a/test/integration/reorganize_pages_spec.mjs +++ b/test/integration/reorganize_pages_spec.mjs @@ -3084,6 +3084,12 @@ describe("Reorganize Pages View", () => { () => parseInt(document.getElementById("pageNumber").max, 10) === 6 ); + // Focus must move to the first newly inserted page (page 3, since + // we merged after page 2). + await page.waitForFunction( + () => window.PDFViewerApplication.page === 3 + ); + // Pages 1–2 come from the original document, then all 3 pages of // the merged PDF, then pages 4–6 of the original shifted to the end. await waitForHavingContents(page, [1, 2, 1, 2, 3, 3]); diff --git a/web/app.js b/web/app.js index bd230a3ca..e630ac5d5 100644 --- a/web/app.js +++ b/web/app.js @@ -1874,7 +1874,8 @@ const PDFViewerApplication = { } this.pdfHistory.initialize({ fingerprint, - resetHistory: viewOnLoad === ViewOnLoad.INITIAL, + resetHistory: + viewOnLoad === ViewOnLoad.INITIAL || !!this._mergedDocumentNeedsSaving, updateUrl: AppOptions.get("historyUpdateUrl"), }); @@ -2440,6 +2441,7 @@ const PDFViewerApplication = { return; } this._mergedDocumentNeedsSaving = true; + this.open({ data: modifiedPdfBytes, filename: this._docFilename, diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js index 3607229bd..70b46dbe4 100644 --- a/web/pdf_thumbnail_viewer.js +++ b/web/pdf_thumbnail_viewer.js @@ -338,7 +338,7 @@ class PDFThumbnailViewer { insertAfter: currentPageIndex ?? -1, }); this.eventBus._on( - "thumbnailsloaded", + "pagesloaded", () => { // Clear any pre-merge selection: thumbnails are rebuilt fresh // (all unchecked), so the old set would cause a label/visual @@ -358,7 +358,10 @@ class PDFThumbnailViewer { this.#selectPage(i + 1, true); } if (insertedPagesCount) { - this.#updateCurrentPage(currentPageIndex + 2); + this.#updateCurrentPage( + currentPageIndex + 2, + /* force = */ true + ); } }, { once: true }