Merge pull request #20800 from calixteman/bug2020731

Once a page has been deleted or pasted, make sure the focus stays in the sidebar (bug 2020731)
This commit is contained in:
calixteman 2026-03-05 22:47:27 +01:00 committed by GitHub
commit 3a80ae47f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 97 additions and 16 deletions

View File

@ -1112,6 +1112,76 @@ describe("Reorganize Pages View", () => {
}); });
}); });
describe("Focus stays in sidebar after page operations (bug 2020731)", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait(
"page_with_number.pdf",
"#viewsManagerToggleButton",
"1",
null,
{ enableSplitMerge: true }
);
});
afterEach(async () => {
await closePages(pages);
});
it("should keep focus on a thumbnail after deleting pages", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await waitForThumbnailVisible(page, 1);
await waitAndClick(
page,
`.thumbnail:has(${getThumbnailSelector(1)}) input`
);
const handlePagesEdited = await waitForPagesEdited(page);
await waitAndClick(page, "#viewsManagerStatusActionButton");
await waitAndClick(page, "#viewsManagerStatusActionDelete");
await awaitPromise(handlePagesEdited);
await page.waitForSelector(
"#thumbnailsView .thumbnailImageContainer:focus",
{
visible: true,
}
);
})
);
});
it("should keep focus on a thumbnail after pasting pages", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await waitForThumbnailVisible(page, 1);
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);
handlePagesEdited = await waitForPagesEdited(page);
await waitAndClick(page, `${getThumbnailSelector(1)}+button`);
await awaitPromise(handlePagesEdited);
await page.waitForSelector(
"#thumbnailsView .thumbnailImageContainer:focus",
{
visible: true,
}
);
})
);
});
});
describe("Extract some pages from a pdf", () => { describe("Extract some pages from a pdf", () => {
let pages; let pages;

View File

@ -125,6 +125,8 @@ class PDFThumbnailViewer {
#copiedPageNumbers = null; #copiedPageNumbers = null;
#boundPastePages = this.#pastePages.bind(this);
#isCut = false; #isCut = false;
#isOneColumnView = false; #isOneColumnView = false;
@ -252,6 +254,15 @@ class PDFThumbnailViewer {
}); });
} }
#resetCurrentThumbnail(newPageNumber) {
if (!this.pdfDocument) {
return;
}
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
thumbnailView?.toggleCurrent(/* isCurrent = */ false);
this._currentPageNumber = newPageNumber;
}
scrollThumbnailIntoView(pageNumber) { scrollThumbnailIntoView(pageNumber) {
if (!this.pdfDocument) { if (!this.pdfDocument) {
return; return;
@ -263,10 +274,8 @@ class PDFThumbnailViewer {
return; return;
} }
if (pageNumber !== this._currentPageNumber) { if (pageNumber !== this._currentPageNumber) {
const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1]; this.#resetCurrentThumbnail(pageNumber);
prevThumbnailView?.toggleCurrent(/* isCurrent = */ false);
thumbnailView.toggleCurrent(/* isCurrent = */ true); thumbnailView.toggleCurrent(/* isCurrent = */ true);
this._currentPageNumber = pageNumber;
} }
const { first, last, views } = this.#getVisibleThumbs(); const { first, last, views } = this.#getVisibleThumbs();
@ -640,10 +649,7 @@ class PDFThumbnailViewer {
type: "move", type: "move",
}); });
setTimeout(() => { this.#updateCurrentPage(currentPageNumber);
this.forceRendering();
this.linkService.goToPage(currentPageNumber);
}, 0);
} }
if (!isNaN(this.#pageNumberToRemove)) { if (!isNaN(this.#pageNumberToRemove)) {
@ -659,6 +665,17 @@ class PDFThumbnailViewer {
this.#selectedPages.clear(); this.#selectedPages.clear();
} }
#updateCurrentPage(currentPageNumber) {
setTimeout(() => {
this.#resetCurrentThumbnail(0);
this.forceRendering();
const newPageNumber = currentPageNumber || 1;
this.linkService.goToPage(newPageNumber);
const thumbnailView = this._thumbnails[newPageNumber - 1];
thumbnailView.imageContainer.focus();
}, 0);
}
#saveExtractedPages() { #saveExtractedPages() {
this.eventBus.dispatch("saveextractedpages", { this.eventBus.dispatch("saveextractedpages", {
source: this, source: this,
@ -688,7 +705,7 @@ class PDFThumbnailViewer {
this.#clearSelection(); this.#clearSelection();
} }
for (const thumbnail of this._thumbnails) { for (const thumbnail of this._thumbnails) {
thumbnail.addPasteButton(this.#pastePages.bind(this)); thumbnail.addPasteButton(this.#boundPastePages);
} }
this.container.classList.add("pasteMode"); this.container.classList.add("pasteMode");
this.#toggleMenuEntries(false); this.#toggleMenuEntries(false);
@ -728,10 +745,7 @@ class PDFThumbnailViewer {
this.#isCut = false; this.#isCut = false;
this.#updateMenuEntries(); this.#updateMenuEntries();
setTimeout(() => { this.#updateCurrentPage(currentPageNumber);
this.forceRendering();
this.linkService.goToPage(currentPageNumber || 1);
}, 0);
} }
#deletePages(type = "delete") { #deletePages(type = "delete") {
@ -757,10 +771,7 @@ class PDFThumbnailViewer {
type, type,
}); });
setTimeout(() => { this.#updateCurrentPage(currentPageNumber);
this.forceRendering();
this.linkService.goToPage(currentPageNumber || 1);
}, 0);
} }
#updateMenuEntries() { #updateMenuEntries() {