Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,7 @@ docs/type3/signatures/

# Claude
.claude/

# Playwright MCP screenshots / traces
.playwright-mcp/
*.playwright-mcp.png
15 changes: 3 additions & 12 deletions frontend/src/core/components/pageEditor/PageThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
onTogglePage,
onExecuteCommand,
onSetStatus,
onSetMovingPage,
onDeletePage,
createRotateCommand,
createSplitCommand,
Expand Down Expand Up @@ -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`);
}
},
Expand All @@ -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`);
}
},
Expand Down Expand Up @@ -391,7 +384,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
[
pageIndex,
totalPages,
movingPage,
isAnimating,
page.pageNumber,
handleRotateLeft,
Expand All @@ -400,7 +392,6 @@ const PageThumbnail: React.FC<PageThumbnailProps> = ({
handleSplit,
handleInsertFileAfter,
onReorderPages,
onSetMovingPage,
onSetStatus,
],
);
Expand Down
26 changes: 12 additions & 14 deletions frontend/src/core/components/pageEditor/commands/pageCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class ReorderPagesCommand extends DOMCommand {
);
if (sourceIndex === -1) return;

const newPages = [...currentDoc.pages];
let reorderedPages: PDFPage[];

if (
this.selectedPages &&
Expand All @@ -246,33 +246,31 @@ 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 =
sourceIndex < this.targetIndex
? 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,
Expand Down
Loading