From bb834b9deecbffdd46d76be451e415c3a1bd2594 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Wed, 6 Mar 2019 01:33:33 -0700 Subject: [PATCH] Reset to original position instead of deleting when selection dropped off-page --- src/control/tools/EditSelection.cpp | 28 +++++++++++---------- src/control/tools/EditSelectionContents.cpp | 16 ++++++++++++ src/control/tools/EditSelectionContents.h | 18 +++++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/control/tools/EditSelection.cpp b/src/control/tools/EditSelection.cpp index ce92f32f..4fef20b8 100644 --- a/src/control/tools/EditSelection.cpp +++ b/src/control/tools/EditSelection.cpp @@ -165,23 +165,25 @@ void EditSelection::finalizeSelection() XojPageView* v = getBestMatchingPageView(); if (v == NULL) - { - this->view->getXournal()->deleteSelection(this); + { // Not on any page - move back to original page and position + this->x = this->contents->getOriginalX(); + this->y = this->contents->getOriginalY(); + v = this->contents->getSourceView(); } - else - { - this->view = v; + - PageRef page = this->view->getPage(); - Layer* layer = page->getSelectedLayer(); - this->contents->finalizeSelection(this->x, this->y, this->width, this->height, - this->aspectRatio, layer, page, this->view, this->undo); + this->view = v; - this->view->rerenderRect(this->x, this->y, this->width, this->height); + PageRef page = this->view->getPage(); + Layer* layer = page->getSelectedLayer(); + this->contents->finalizeSelection(this->x, this->y, this->width, this->height, + this->aspectRatio, layer, page, this->view, this->undo); + + this->view->rerenderRect(this->x, this->y, this->width, this->height); + + // This is needed if the selection not was 100% on a page + this->view->getXournal()->repaintSelection(true); - // This is needed if the selection not was 100% on a page - this->view->getXournal()->repaintSelection(true); - } } /** diff --git a/src/control/tools/EditSelectionContents.cpp b/src/control/tools/EditSelectionContents.cpp index 5736a28d..c030907d 100644 --- a/src/control/tools/EditSelectionContents.cpp +++ b/src/control/tools/EditSelectionContents.cpp @@ -429,6 +429,22 @@ void EditSelectionContents::finalizeSelection(double x, double y, double width, } +double EditSelectionContents::getOriginalX() +{ + return this->originalX; +} + +double EditSelectionContents::getOriginalY() +{ + return this->originalY; +} + +XojPageView* EditSelectionContents::getSourceView() +{ + return this->sourceView; +} + + void EditSelectionContents::updateContent(double x, double y, double rotation, double width, double height, bool aspectRatio, Layer* layer, PageRef targetPage, XojPageView* targetView, UndoRedoHandler* undo, CursorSelectionType type) diff --git a/src/control/tools/EditSelectionContents.h b/src/control/tools/EditSelectionContents.h index 7d467685..767e3a21 100644 --- a/src/control/tools/EditSelectionContents.h +++ b/src/control/tools/EditSelectionContents.h @@ -108,6 +108,24 @@ private: static bool repaintSelection(EditSelectionContents* selection); public: + + /** + * Gets the original view of the contents + */ + XojPageView * getSourceView(); + + + /** + * Gets the original X of the contents + */ + double getOriginalX(); + + /** + * Gets the original Y of the contents + */ + double getOriginalY(); + + /** * Gets the original width of the contents */