mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 14:19:24 +00:00
Fix page break selection
This commit is contained in:
parent
185ddb7dc0
commit
6de5f92e83
@ -454,7 +454,20 @@ export class PageBreakCommand extends DOMCommand {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setDocument(updatedDocument);
|
this.setDocument(updatedDocument);
|
||||||
this.setSelectedPages([]);
|
|
||||||
|
// Maintain existing selection by mapping original selected pages to their new positions
|
||||||
|
const updatedSelection: number[] = [];
|
||||||
|
this.selectedPageNumbers.forEach(originalPageNum => {
|
||||||
|
// Find the original page by matching the page ID from the original document
|
||||||
|
const originalPage = this.originalDocument?.pages[originalPageNum - 1];
|
||||||
|
if (originalPage) {
|
||||||
|
const foundPage = newPages.find(page => page.id === originalPage.id && !page.isBlankPage);
|
||||||
|
if (foundPage) {
|
||||||
|
updatedSelection.push(foundPage.pageNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setSelectedPages(updatedSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
undo(): void {
|
undo(): void {
|
||||||
@ -470,11 +483,13 @@ export class PageBreakCommand extends DOMCommand {
|
|||||||
export class BulkPageBreakCommand extends DOMCommand {
|
export class BulkPageBreakCommand extends DOMCommand {
|
||||||
private insertedPages: PDFPage[] = [];
|
private insertedPages: PDFPage[] = [];
|
||||||
private originalDocument: PDFDocument | null = null;
|
private originalDocument: PDFDocument | null = null;
|
||||||
|
private originalSelectedPages: number[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private getCurrentDocument: () => PDFDocument | null,
|
private getCurrentDocument: () => PDFDocument | null,
|
||||||
private setDocument: (doc: PDFDocument) => void,
|
private setDocument: (doc: PDFDocument) => void,
|
||||||
private setSelectedPages: (pages: number[]) => void
|
private setSelectedPages: (pages: number[]) => void,
|
||||||
|
private getSelectedPages: () => number[]
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -483,6 +498,9 @@ export class BulkPageBreakCommand extends DOMCommand {
|
|||||||
const currentDoc = this.getCurrentDocument();
|
const currentDoc = this.getCurrentDocument();
|
||||||
if (!currentDoc) return;
|
if (!currentDoc) return;
|
||||||
|
|
||||||
|
// Store original selection to restore later
|
||||||
|
this.originalSelectedPages = this.getSelectedPages();
|
||||||
|
|
||||||
// Store original state for undo
|
// Store original state for undo
|
||||||
this.originalDocument = {
|
this.originalDocument = {
|
||||||
...currentDoc,
|
...currentDoc,
|
||||||
@ -524,7 +542,20 @@ export class BulkPageBreakCommand extends DOMCommand {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setDocument(updatedDocument);
|
this.setDocument(updatedDocument);
|
||||||
this.setSelectedPages([]);
|
|
||||||
|
// Maintain existing selection by mapping original selected pages to their new positions
|
||||||
|
const updatedSelection: number[] = [];
|
||||||
|
this.originalSelectedPages.forEach(originalPageNum => {
|
||||||
|
// Find the original page by matching the page ID from the original document
|
||||||
|
const originalPage = this.originalDocument?.pages[originalPageNum - 1];
|
||||||
|
if (originalPage) {
|
||||||
|
const foundPage = newPages.find(page => page.id === originalPage.id && !page.isBlankPage);
|
||||||
|
if (foundPage) {
|
||||||
|
updatedSelection.push(foundPage.pageNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setSelectedPages(updatedSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
undo(): void {
|
undo(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user