Don't enable undo in stroke view for items created before stroke view.

pull/2/head
Matthew Chen 6 years ago
parent 5091587ed6
commit 65ead451c0

@ -23,6 +23,11 @@ public class ImageEditorBrushViewController: OWSViewController {
private var brushGestureRecognizer: ImageEditorPanGestureRecognizer?
// We only want to let users undo changes made in this view.
// So we snapshot any older "operation id" and prevent
// users from undoing it.
private let firstUndoOperationId: String?
init(delegate: ImageEditorBrushViewControllerDelegate,
model: ImageEditorModel,
currentColor: ImageEditorColor) {
@ -30,6 +35,7 @@ public class ImageEditorBrushViewController: OWSViewController {
self.model = model
self.canvasView = ImageEditorCanvasView(model: model)
self.paletteView = ImageEditorPaletteView(currentColor: currentColor)
self.firstUndoOperationId = model.currentUndoOperationId()
super.init(nibName: nil, bundle: nil)
@ -86,8 +92,10 @@ public class ImageEditorBrushViewController: OWSViewController {
let doneButton = navigationBarButton(imageName: "image_editor_checkmark_full",
selector: #selector(didTapDone(sender:)))
// Prevent users from undo any changes made before entering the view.
let canUndo = model.canUndo() && firstUndoOperationId != model.currentUndoOperationId()
var navigationBarItems = [UIView]()
if model.canUndo() {
if canUndo {
navigationBarItems = [undoButton, doneButton]
} else {
navigationBarItems = [doneButton]

@ -242,9 +242,12 @@ public class ImageEditorTransform: NSObject {
// (multiple times) to preserve/restore editor state.
private class ImageEditorOperation: NSObject {
let operationId: String
let contents: ImageEditorContents
required init(contents: ImageEditorContents) {
self.operationId = UUID().uuidString
self.contents = contents
}
}
@ -361,6 +364,14 @@ public class ImageEditorModel: NSObject {
return !redoStack.isEmpty
}
@objc
public func currentUndoOperationId() -> String? {
guard let operation = undoStack.last else {
return nil
}
return operation.operationId
}
// MARK: - Observers
private var observers = [Weak<ImageEditorModelObserver>]()

Loading…
Cancel
Save