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:
Reece Browne
2026-05-05 20:46:47 +00:00
committed by GitHub
co-authored by EthanHealy01
parent c892b985e2
commit ed56490f93
3 changed files with 19 additions and 26 deletions
+4
View File
@@ -266,3 +266,7 @@ docs/type3/signatures/
# Claude
.claude/
# Playwright MCP screenshots / traces
.playwright-mcp/
*.playwright-mcp.png
@@ -88,7 +88,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
onTogglePage,
onExecuteCommand,
onSetStatus,
onSetMovingPage,
onDeletePage,
createRotateCommand,
createSplitCommand,
@@ -328,10 +327,8 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
label: "Move Left",
onClick: (e) => {
e.stopPropagation();
if (pageIndex > 0 && !movingPage && !isAnimating) {
onSetMovingPage(page.pageNumber);
if (pageIndex > 0 && !isAnimating) {
onReorderPages(page.pageNumber, pageIndex - 1);
setTimeout(() => onSetMovingPage(null), 650);
onSetStatus(`Moved page ${page.pageNumber} left`);
}
},
@@ -343,13 +340,9 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
label: "Move Right",
onClick: (e) => {
e.stopPropagation();
if (pageIndex < totalPages - 1 && !movingPage && !isAnimating) {
onSetMovingPage(page.pageNumber);
// 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.
if (pageIndex < totalPages - 1 && !isAnimating) {
// +2 compensates for ReorderPagesCommand's internal targetIndex - 1 adjustment.
onReorderPages(page.pageNumber, pageIndex + 2);
setTimeout(() => onSetMovingPage(null), 650);
onSetStatus(`Moved page ${page.pageNumber} right`);
}
},
@@ -391,7 +384,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
[
pageIndex,
totalPages,
movingPage,
isAnimating,
page.pageNumber,
handleRotateLeft,
@@ -400,7 +392,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
handleSplit,
handleInsertFileAfter,
onReorderPages,
onSetMovingPage,
onSetStatus,
],
);
@@ -232,7 +232,7 @@ export class ReorderPagesCommand extends DOMCommand {
);
if (sourceIndex === -1) return;
const newPages = [...currentDoc.pages];
let reorderedPages: PDFPage[];
if (
this.selectedPages &&
@@ -246,19 +246,15 @@ export class ReorderPagesCommand extends DOMCommand {
)
.filter((page) => page !== undefined) as PDFPage[];
const remainingPages = newPages.filter(
const remainingPages = currentDoc.pages.filter(
(page) => !this.selectedPages!.includes(page.pageNumber),
);
remainingPages.splice(this.targetIndex, 0, ...selectedPageObjects);
remainingPages.forEach((page, index) => {
page.pageNumber = index + 1;
});
newPages.splice(0, newPages.length, ...remainingPages);
reorderedPages = remainingPages;
} else {
// 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)
const adjustedTargetIndex =
@@ -266,13 +262,15 @@ export class ReorderPagesCommand extends DOMCommand {
? this.targetIndex - 1
: this.targetIndex;
newPages.splice(adjustedTargetIndex, 0, movedPage);
newPages.forEach((page, index) => {
page.pageNumber = index + 1;
});
working.splice(adjustedTargetIndex, 0, movedPage);
reorderedPages = working;
}
const newPages = reorderedPages.map((page, index) => ({
...page,
pageNumber: index + 1,
}));
const reorderedDocument: PDFDocument = {
...currentDoc,
pages: newPages,