diff --git a/src/main/resources/static/js/multitool/DragDropManager.js b/src/main/resources/static/js/multitool/DragDropManager.js index 5eefd9576..7cbe97ab0 100644 --- a/src/main/resources/static/js/multitool/DragDropManager.js +++ b/src/main/resources/static/js/multitool/DragDropManager.js @@ -114,13 +114,15 @@ class DragDropManager { } else { this.selectedPageElements.forEach((pageEl) => { pageEl.classList.remove('drag-manager_dragging'); + }); - if (this.hoveredEl === this.endInsertionElement) { - this.movePageTo(pageEl); - } else { - this.movePageTo(pageEl, this.hoveredEl); - } + this.movePageTo( + this.selectedPageElements, + this.hoveredEl === this.endInsertionElement + ? null + : this.hoveredEl); + this.selectedPageElements.forEach((pageEl) => { // Handle timeout for the current element this.handleTimeoutForElement(pageEl); }); diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 3ea652760..f9955a71c 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -6,6 +6,7 @@ import { UndoManager } from './UndoManager.js'; import { PageBreakCommand } from './commands/page-break.js'; import { AddFilesCommand } from './commands/add-page.js'; import { DecryptFile } from '../DecryptFiles.js'; +import { CommandSequence } from './commands/commands-sequence.js'; class PdfContainer { fileName; @@ -109,9 +110,33 @@ class PdfContainer { downloadBtn.disabled = true; } - movePageTo(startElement, endElement, scrollTo = false) { + movePagesTo(startElements, endElement, scrollTo = false) { + let commands = []; + startElements.forEach((page) => { + let command = new MovePageCommand( + page, + endElement, + this.pagesContainer, + this.pagesContainerWrapper, + scrollTo + ) + command.execute(); + commands.push(command); + }) + + let commandSequence = new CommandSequence(commands); + this.undoManager.pushUndoClearRedo(commandSequence); + return commandSequence; + } + + movePageTo(startElements, endElement, scrollTo = false) { + + if (Array.isArray(startElements)){ + return this.movePagesTo(startElements, endElement, scrollTo = false); + } + let movePageCommand = new MovePageCommand( - startElement, + startElements, endElement, this.pagesContainer, this.pagesContainerWrapper, diff --git a/src/main/resources/static/js/multitool/commands/commands-sequence.js b/src/main/resources/static/js/multitool/commands/commands-sequence.js new file mode 100644 index 000000000..61d2ba469 --- /dev/null +++ b/src/main/resources/static/js/multitool/commands/commands-sequence.js @@ -0,0 +1,20 @@ +import {Command} from './command.js'; + +export class CommandSequence extends Command { + constructor(commands) { + super(); + this.commands = commands; + + } + execute() { + this.commands.forEach((command) => command.execute()) + } + + undo() { + this.commands.slice().reverse().forEach((command) => command.undo()) + } + + redo() { + this.execute(); + } +}