Fixed undo/redo bug

This commit is contained in:
Jaex 2023-12-27 10:06:42 +03:00
parent e5fe1a8e70
commit aa6f127825

View file

@ -191,6 +191,9 @@ private set
public bool IsCurrentHoverShapeValid => CurrentHoverShape != null && CurrentHoverShape.IsValidShape; public bool IsCurrentHoverShapeValid => CurrentHoverShape != null && CurrentHoverShape.IsValidShape;
public bool IsCurrentShapeTypeRegion => IsShapeTypeRegion(CurrentTool); public bool IsCurrentShapeTypeRegion => IsShapeTypeRegion(CurrentTool);
public bool IsCurrentShapeTypeTool => IsShapeTypeTool(CurrentTool);
public int StartingStepNumber { get; set; } = 1; public int StartingStepNumber { get; set; } = 1;
public bool IsCreating { get; set; } public bool IsCreating { get; set; }
@ -956,10 +959,12 @@ public void StartRegionSelection()
if (shape != null && shape.IsSelectable) // Select shape if (shape != null && shape.IsSelectable) // Select shape
{ {
DeselectCurrentShape(); DeselectCurrentShape();
if (!IsMoving) if (!IsMoving)
{ {
history.CreateShapesMemento(); history.CreateShapesMemento();
} }
IsMoving = true; IsMoving = true;
shape.OnMoving(); shape.OnMoving();
CurrentShape = shape; CurrentShape = shape;
@ -974,7 +979,12 @@ public void StartRegionSelection()
{ {
ClearTools(); ClearTools();
DeselectCurrentShape(); DeselectCurrentShape();
history.CreateShapesMemento();
if (!IsCurrentShapeTypeRegion && !IsCurrentShapeTypeTool)
{
history.CreateShapesMemento();
}
shape = AddShape(); shape = AddShape();
shape.OnCreating(); shape.OnCreating();
} }
@ -1558,6 +1568,8 @@ public void RestoreState(ImageEditorMemento memento)
effect.OnMoved(); effect.OnMoved();
} }
ClearTools();
DeselectCurrentShape();
OnImageModified(); OnImageModified();
UpdateMenu(); UpdateMenu();
} }
@ -1789,6 +1801,19 @@ private bool IsShapeTypeRegion(ShapeType shapeType)
return false; return false;
} }
private bool IsShapeTypeTool(ShapeType shapeType)
{
switch (shapeType)
{
case ShapeType.ToolSelect:
case ShapeType.ToolCrop:
case ShapeType.ToolCutOut:
return true;
}
return false;
}
private void UpdateNodes() private void UpdateNodes()
{ {
BaseShape shape = CurrentShape; BaseShape shape = CurrentShape;