mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Multipage drag and drop undo fix
This commit is contained in:
parent
819c138654
commit
71e13d8e47
@ -114,13 +114,15 @@ class DragDropManager {
|
|||||||
} else {
|
} else {
|
||||||
this.selectedPageElements.forEach((pageEl) => {
|
this.selectedPageElements.forEach((pageEl) => {
|
||||||
pageEl.classList.remove('drag-manager_dragging');
|
pageEl.classList.remove('drag-manager_dragging');
|
||||||
|
});
|
||||||
|
|
||||||
if (this.hoveredEl === this.endInsertionElement) {
|
this.movePageTo(
|
||||||
this.movePageTo(pageEl);
|
this.selectedPageElements,
|
||||||
} else {
|
this.hoveredEl === this.endInsertionElement
|
||||||
this.movePageTo(pageEl, this.hoveredEl);
|
? null
|
||||||
}
|
: this.hoveredEl);
|
||||||
|
|
||||||
|
this.selectedPageElements.forEach((pageEl) => {
|
||||||
// Handle timeout for the current element
|
// Handle timeout for the current element
|
||||||
this.handleTimeoutForElement(pageEl);
|
this.handleTimeoutForElement(pageEl);
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ import { UndoManager } from './UndoManager.js';
|
|||||||
import { PageBreakCommand } from './commands/page-break.js';
|
import { PageBreakCommand } from './commands/page-break.js';
|
||||||
import { AddFilesCommand } from './commands/add-page.js';
|
import { AddFilesCommand } from './commands/add-page.js';
|
||||||
import { DecryptFile } from '../DecryptFiles.js';
|
import { DecryptFile } from '../DecryptFiles.js';
|
||||||
|
import { CommandSequence } from './commands/commands-sequence.js';
|
||||||
|
|
||||||
class PdfContainer {
|
class PdfContainer {
|
||||||
fileName;
|
fileName;
|
||||||
@ -109,9 +110,33 @@ class PdfContainer {
|
|||||||
downloadBtn.disabled = true;
|
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(
|
let movePageCommand = new MovePageCommand(
|
||||||
startElement,
|
startElements,
|
||||||
endElement,
|
endElement,
|
||||||
this.pagesContainer,
|
this.pagesContainer,
|
||||||
this.pagesContainerWrapper,
|
this.pagesContainerWrapper,
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user