Skip to content

Commit

Permalink
Merge pull request #3 from IdeasOnCanvas/enhancement/discardUndoHistory
Browse files Browse the repository at this point in the history
discard redo history when document is closed
  • Loading branch information
Patrick-Kladek authored Dec 22, 2017
2 parents 42a7183 + 5b34ec5 commit bd091b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Screenshot Framer/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ final class Document: NSDocument {
return true
}

override func canClose(withDelegate delegate: Any, shouldClose shouldCloseSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
self.layerStateHistory.discardRedoHistory()

if self.isDocumentEdited && self.fileURL != nil {
self.save(nil)
}
self.close()
}


// Responder Chain

@IBAction func showTimeTravelWindow(_ sender: AnyObject?) {
Expand Down
8 changes: 8 additions & 0 deletions Screenshot Framer/Model/LayerStateHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ final class LayerStateHistory {
self.notifyLayerStateDidChange()
}

@discardableResult func discardRedoHistory() -> Bool {
guard self.currentStackPosition < self.layerStates.count - 1 else { return false }

let delta = (self.layerStates.count - 1) - self.currentStackPosition
self.layerStates.removeLast(delta)
return true
}


// MARK: - Undo / Redo

Expand Down
2 changes: 1 addition & 1 deletion Screenshot Framer/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>3</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down

0 comments on commit bd091b2

Please sign in to comment.