mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Fix move button on multitool (#6291)
Hitting move button twice on multitool didn't work --------- Co-authored-by: EthanHealy01 <[email protected]>
This commit is contained in:
co-authored by
EthanHealy01
parent
c892b985e2
commit
ed56490f93
@@ -266,3 +266,7 @@ docs/type3/signatures/
|
|||||||
|
|
||||||
# Claude
|
# Claude
|
||||||
.claude/
|
.claude/
|
||||||
|
|
||||||
|
# Playwright MCP screenshots / traces
|
||||||
|
.playwright-mcp/
|
||||||
|
*.playwright-mcp.png
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
|
|||||||
onTogglePage,
|
onTogglePage,
|
||||||
onExecuteCommand,
|
onExecuteCommand,
|
||||||
onSetStatus,
|
onSetStatus,
|
||||||
onSetMovingPage,
|
|
||||||
onDeletePage,
|
onDeletePage,
|
||||||
createRotateCommand,
|
createRotateCommand,
|
||||||
createSplitCommand,
|
createSplitCommand,
|
||||||
@@ -328,10 +327,8 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
|
|||||||
label: "Move Left",
|
label: "Move Left",
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (pageIndex > 0 && !movingPage && !isAnimating) {
|
if (pageIndex > 0 && !isAnimating) {
|
||||||
onSetMovingPage(page.pageNumber);
|
|
||||||
onReorderPages(page.pageNumber, pageIndex - 1);
|
onReorderPages(page.pageNumber, pageIndex - 1);
|
||||||
setTimeout(() => onSetMovingPage(null), 650);
|
|
||||||
onSetStatus(`Moved page ${page.pageNumber} left`);
|
onSetStatus(`Moved page ${page.pageNumber} left`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -343,13 +340,9 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
|
|||||||
label: "Move Right",
|
label: "Move Right",
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (pageIndex < totalPages - 1 && !movingPage && !isAnimating) {
|
if (pageIndex < totalPages - 1 && !isAnimating) {
|
||||||
onSetMovingPage(page.pageNumber);
|
// +2 compensates for ReorderPagesCommand's internal targetIndex - 1 adjustment.
|
||||||
// ReorderPagesCommand expects target index relative to the original array.
|
|
||||||
// When moving toward the right (higher index), provide desiredIndex + 1
|
|
||||||
// so the command's internal adjustment (targetIndex - 1) lands correctly.
|
|
||||||
onReorderPages(page.pageNumber, pageIndex + 2);
|
onReorderPages(page.pageNumber, pageIndex + 2);
|
||||||
setTimeout(() => onSetMovingPage(null), 650);
|
|
||||||
onSetStatus(`Moved page ${page.pageNumber} right`);
|
onSetStatus(`Moved page ${page.pageNumber} right`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -391,7 +384,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
|
|||||||
[
|
[
|
||||||
pageIndex,
|
pageIndex,
|
||||||
totalPages,
|
totalPages,
|
||||||
movingPage,
|
|
||||||
isAnimating,
|
isAnimating,
|
||||||
page.pageNumber,
|
page.pageNumber,
|
||||||
handleRotateLeft,
|
handleRotateLeft,
|
||||||
@@ -400,7 +392,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
|
|||||||
handleSplit,
|
handleSplit,
|
||||||
handleInsertFileAfter,
|
handleInsertFileAfter,
|
||||||
onReorderPages,
|
onReorderPages,
|
||||||
onSetMovingPage,
|
|
||||||
onSetStatus,
|
onSetStatus,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ export class ReorderPagesCommand extends DOMCommand {
|
|||||||
);
|
);
|
||||||
if (sourceIndex === -1) return;
|
if (sourceIndex === -1) return;
|
||||||
|
|
||||||
const newPages = [...currentDoc.pages];
|
let reorderedPages: PDFPage[];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.selectedPages &&
|
this.selectedPages &&
|
||||||
@@ -246,19 +246,15 @@ export class ReorderPagesCommand extends DOMCommand {
|
|||||||
)
|
)
|
||||||
.filter((page) => page !== undefined) as PDFPage[];
|
.filter((page) => page !== undefined) as PDFPage[];
|
||||||
|
|
||||||
const remainingPages = newPages.filter(
|
const remainingPages = currentDoc.pages.filter(
|
||||||
(page) => !this.selectedPages!.includes(page.pageNumber),
|
(page) => !this.selectedPages!.includes(page.pageNumber),
|
||||||
);
|
);
|
||||||
remainingPages.splice(this.targetIndex, 0, ...selectedPageObjects);
|
remainingPages.splice(this.targetIndex, 0, ...selectedPageObjects);
|
||||||
|
reorderedPages = remainingPages;
|
||||||
remainingPages.forEach((page, index) => {
|
|
||||||
page.pageNumber = index + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
newPages.splice(0, newPages.length, ...remainingPages);
|
|
||||||
} else {
|
} else {
|
||||||
// Single page reorder
|
// Single page reorder
|
||||||
const [movedPage] = newPages.splice(sourceIndex, 1);
|
const working = [...currentDoc.pages];
|
||||||
|
const [movedPage] = working.splice(sourceIndex, 1);
|
||||||
|
|
||||||
// Adjust target index if moving forward (after removal, indices shift)
|
// Adjust target index if moving forward (after removal, indices shift)
|
||||||
const adjustedTargetIndex =
|
const adjustedTargetIndex =
|
||||||
@@ -266,13 +262,15 @@ export class ReorderPagesCommand extends DOMCommand {
|
|||||||
? this.targetIndex - 1
|
? this.targetIndex - 1
|
||||||
: this.targetIndex;
|
: this.targetIndex;
|
||||||
|
|
||||||
newPages.splice(adjustedTargetIndex, 0, movedPage);
|
working.splice(adjustedTargetIndex, 0, movedPage);
|
||||||
|
reorderedPages = working;
|
||||||
newPages.forEach((page, index) => {
|
|
||||||
page.pageNumber = index + 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newPages = reorderedPages.map((page, index) => ({
|
||||||
|
...page,
|
||||||
|
pageNumber: index + 1,
|
||||||
|
}));
|
||||||
|
|
||||||
const reorderedDocument: PDFDocument = {
|
const reorderedDocument: PDFDocument = {
|
||||||
...currentDoc,
|
...currentDoc,
|
||||||
pages: newPages,
|
pages: newPages,
|
||||||
|
|||||||
Reference in New Issue
Block a user