From 18c41080a6084ef4b05d649b6fefe8255e5638a9 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 19 Jun 2018 10:33:57 +0200 Subject: [PATCH] BUG-2300: A small fix for the undo/redo issue in the editor, where the moves are not merged. --- .../Drawing/Adorners/MoveAdorner.cs | 12 ++++++++---- .../DrawableContainerBoundsChangeMemento.cs | 15 ++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Greenshot.Addon.LegacyEditor/Drawing/Adorners/MoveAdorner.cs b/src/Greenshot.Addon.LegacyEditor/Drawing/Adorners/MoveAdorner.cs index 32026e1b4..36b5fc852 100644 --- a/src/Greenshot.Addon.LegacyEditor/Drawing/Adorners/MoveAdorner.cs +++ b/src/Greenshot.Addon.LegacyEditor/Drawing/Adorners/MoveAdorner.cs @@ -42,7 +42,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Adorners { private NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty; private NativeRectFloat _boundsBeforeResize = NativeRectFloat.Empty; - + private bool _initialMoveAfterMouseDown = true; public MoveAdorner(IDrawableContainer owner, Positions position) : base(owner) { Position = position; @@ -112,6 +112,8 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Adorners EditStatus = EditStatus.RESIZING; _boundsBeforeResize = new NativeRectFloat(Owner.Left, Owner.Top, Owner.Width, Owner.Height); _boundsAfterResize = _boundsBeforeResize; + _initialMoveAfterMouseDown = true; + } /// @@ -126,10 +128,12 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Adorners return; } Owner.Invalidate(); - Owner.MakeBoundsChangeUndoable(false); + // Make merges in this drag, meaning as long as it's not the initial move we merge + Owner.MakeBoundsChangeUndoable(!_initialMoveAfterMouseDown); + _initialMoveAfterMouseDown = false; - // reset "workbench" rectangle to current bounds - _boundsAfterResize = _boundsBeforeResize; + // reset "workbench" rectangle to current bounds + _boundsAfterResize = _boundsBeforeResize; // calculate scaled rectangle ScaleHelper.Scale(ref _boundsAfterResize, Position, new NativePointFloat(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions()); diff --git a/src/Greenshot.Addon.LegacyEditor/Memento/DrawableContainerBoundsChangeMemento.cs b/src/Greenshot.Addon.LegacyEditor/Memento/DrawableContainerBoundsChangeMemento.cs index 25d4b46ff..6906ff64c 100644 --- a/src/Greenshot.Addon.LegacyEditor/Memento/DrawableContainerBoundsChangeMemento.cs +++ b/src/Greenshot.Addon.LegacyEditor/Memento/DrawableContainerBoundsChangeMemento.cs @@ -66,14 +66,15 @@ namespace Greenshot.Addon.LegacyEditor.Memento public bool Merge(IMemento otherMemento) { - var other = otherMemento as DrawableContainerBoundsChangeMemento; - if (other != null) + if (!(otherMemento is DrawableContainerBoundsChangeMemento other)) { - if (ObjectExtensions.CompareLists(_listOfdrawableContainer, other._listOfdrawableContainer)) - { - // Lists are equal, as we have the state already we can ignore the new memento - return true; - } + return false; + } + + if (ObjectExtensions.CompareLists(_listOfdrawableContainer, other._listOfdrawableContainer)) + { + // Lists are equal, as we have the state already we can ignore the new memento + return true; } return false; }