diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift
index 34486a0..0ace6d9 100644
--- a/Memola/Canvas/Contexts/GraphicContext.swift
+++ b/Memola/Canvas/Contexts/GraphicContext.swift
@@ -42,15 +42,27 @@ class GraphicContext: NSManagedObject {
func undoGraphic() {
guard let stroke = strokes.lastObject as? Stroke else { return }
strokes.remove(stroke)
+ stroke.graphicContext = nil
previousStroke = nil
+ do {
+ try Persistence.shared.viewContext.save()
+ } catch {
+ NSLog("[Memola] - \(error.localizedDescription)")
+ }
}
func redoGraphic(for event: HistoryEvent) {
switch event {
case .stroke(let stroke):
strokes.add(stroke)
+ stroke.graphicContext = self
previousStroke = nil
}
+ do {
+ try Persistence.shared.viewContext.save()
+ } catch {
+ NSLog("[Memola] - \(error.localizedDescription)")
+ }
}
}
@@ -109,8 +121,15 @@ extension GraphicContext {
}
func cancelStroke() {
- if let stroke = strokes.lastObject {
- strokes.remove(stroke)
+ if let stroke = strokes.lastObject as? Stroke {
+ do {
+ let viewContext = Persistence.shared.viewContext
+ strokes.remove(stroke)
+ viewContext.delete(stroke)
+ try viewContext.save()
+ } catch {
+ NSLog("[Memola] - \(error.localizedDescription)")
+ }
}
currentStroke = nil
currentPoint = nil
diff --git a/Memola/Features/Memo/MemoView.swift b/Memola/Features/Memo/MemoView.swift
index 876f4e7..b933020 100644
--- a/Memola/Features/Memo/MemoView.swift
+++ b/Memola/Features/Memo/MemoView.swift
@@ -88,6 +88,7 @@ struct MemoView: View {
}
func closeMemo() {
+ history.resetRedo()
if managedObjectContext.hasChanges {
do {
try managedObjectContext.save()
diff --git a/Memola/Resources/Models/MemolaModel.xcdatamodeld/MemolaModel.xcdatamodel/contents b/Memola/Resources/Models/MemolaModel.xcdatamodeld/MemolaModel.xcdatamodel/contents
index c2bf94d..0592f91 100644
--- a/Memola/Resources/Models/MemolaModel.xcdatamodeld/MemolaModel.xcdatamodel/contents
+++ b/Memola/Resources/Models/MemolaModel.xcdatamodeld/MemolaModel.xcdatamodel/contents
@@ -23,7 +23,7 @@
-
+