From 2e254dc4af38200b3cef7781e72df482a67ac938 Mon Sep 17 00:00:00 2001 From: dscyrescotti Date: Mon, 10 Jun 2024 22:53:29 +0700 Subject: [PATCH] feat: refresh objects --- Memola/Canvas/Contexts/GraphicContext.swift | 7 +++++++ Memola/Canvas/Core/Canvas.swift | 1 + 2 files changed, 8 insertions(+) diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift index 9467fc1..a9ccfda 100644 --- a/Memola/Canvas/Contexts/GraphicContext.swift +++ b/Memola/Canvas/Contexts/GraphicContext.swift @@ -52,6 +52,7 @@ final class GraphicContext: @unchecked Sendable { withPersistence(\.backgroundContext) { [stroke = deletedStroke] context in stroke?.stroke(as: PenStroke.self)?.object?.graphicContext = nil try context.saveIfNeeded() + context.refreshAllObjects() } case .eraser: guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else { return } @@ -64,6 +65,8 @@ final class GraphicContext: @unchecked Sendable { penStroke.object?.erasers.remove(object) } } + try context.saveIfNeeded() + context.refreshAllObjects() } } previousStroke = nil @@ -82,6 +85,7 @@ final class GraphicContext: @unchecked Sendable { withPersistence(\.backgroundContext) { [weak self, penStroke] context in penStroke.object?.graphicContext = self?.object try context.saveIfNeeded() + context.refreshAllObjects() } case .eraser: guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else { @@ -97,6 +101,7 @@ final class GraphicContext: @unchecked Sendable { } } try context.saveIfNeeded() + context.refreshAllObjects() } } previousStroke = nil @@ -120,12 +125,14 @@ extension GraphicContext { withPersistenceSync(\.newBackgroundContext) { [_stroke] context in guard let stroke = try? context.existingObject(with: id) as? StrokeObject else { return } _stroke.loadQuads(from: stroke, with: self) + context.refreshAllObjects() } } } else { withPersistence(\.backgroundContext) { [weak self] context in guard let self else { return } _stroke.loadQuads(with: self) + context.refreshAllObjects() } } } diff --git a/Memola/Canvas/Core/Canvas.swift b/Memola/Canvas/Core/Canvas.swift index 3a5931b..821d953 100644 --- a/Memola/Canvas/Core/Canvas.swift +++ b/Memola/Canvas/Core/Canvas.swift @@ -69,6 +69,7 @@ extension Canvas { func loadStrokes(_ bounds: CGRect) { withPersistence(\.backgroundContext) { [weak self, bounds] context in self?.graphicContext.loadQuads(bounds, on: context) + context.refreshAllObjects() } } }