diff --git a/src/core/control/tools/EditSelection.cpp b/src/core/control/tools/EditSelection.cpp index e868e3b0cc87..aa2c54c6627a 100644 --- a/src/core/control/tools/EditSelection.cpp +++ b/src/core/control/tools/EditSelection.cpp @@ -753,7 +753,7 @@ void EditSelection::updateMatrix() { cairo_matrix_translate(&this->cmatrix, -rx, -ry); } -void EditSelection::moveSelection(double dx, double dy) { +void EditSelection::moveSelection(double dx, double dy, bool addMoveUndo) { this->x += dx; this->y += dy; this->snappedBounds.x += dx; @@ -761,6 +761,10 @@ void EditSelection::moveSelection(double dx, double dy) { updateMatrix(); + if (addMoveUndo) { + this->contents->addMoveUndo(this->undo, dx, dy); + } + this->view->getXournal()->repaintSelection(); } diff --git a/src/core/control/tools/EditSelection.h b/src/core/control/tools/EditSelection.h index 38b30d229fa2..72d203eb2502 100644 --- a/src/core/control/tools/EditSelection.h +++ b/src/core/control/tools/EditSelection.h @@ -220,7 +220,7 @@ class EditSelection: public ElementContainer, public Serializable { /** * Move the selection */ - void moveSelection(double dx, double dy); + void moveSelection(double dx, double dy, bool addMoveUndo = false); /** * Get the cursor type for the current position (if 0 then the default cursor should be used) diff --git a/src/core/control/tools/EditSelectionContents.cpp b/src/core/control/tools/EditSelectionContents.cpp index f128b848bfb5..ae3e3b62e8e4 100644 --- a/src/core/control/tools/EditSelectionContents.cpp +++ b/src/core/control/tools/EditSelectionContents.cpp @@ -82,6 +82,15 @@ void EditSelectionContents::replaceInsertOrder(std::dequeinsertOrder = std::move(newInsertOrder); } +void EditSelectionContents::addMoveUndo(UndoRedoHandler* undo, double dx, double dy) { + undo->addUndoAction(std::make_unique(this->sourceLayer, this->sourcePage, &this->selected, dx, dy, + this->sourceLayer, this->sourcePage)); + this->lastBounds.x += dx; + this->lastBounds.y += dy; + this->lastSnappedBounds.x += dx; + this->lastSnappedBounds.y += dy; +} + /** * Returns all containing elements of this selection */ diff --git a/src/core/control/tools/EditSelectionContents.h b/src/core/control/tools/EditSelectionContents.h index bce9fdab14ba..b11e1af4fb74 100644 --- a/src/core/control/tools/EditSelectionContents.h +++ b/src/core/control/tools/EditSelectionContents.h @@ -104,6 +104,8 @@ class EditSelectionContents: public ElementContainer, public Serializable { * */ void replaceInsertOrder(std::deque> newInsertOrder); + void addMoveUndo(UndoRedoHandler* undo, double dx, double dy); + public: /** * paints the selection diff --git a/src/core/gui/XournalView.cpp b/src/core/gui/XournalView.cpp index 154978194547..d5201654ee7e 100644 --- a/src/core/gui/XournalView.cpp +++ b/src/core/gui/XournalView.cpp @@ -169,7 +169,7 @@ auto XournalView::onKeyPressEvent(GdkEventKey* event) -> bool { ydir = 1; } if (xdir != 0 || ydir != 0) { - selection->moveSelection(d * xdir, d * ydir); + selection->moveSelection(d * xdir, d * ydir, true); selection->ensureWithinVisibleArea(); return true; }