How to Fix When Some Text Changes Don't Come with Automatic Undo?
When you work with NSTextView
and happen to use insertText(_:)
to programmatically insert text, you get an undoable action for free. This might give the impression you get undo/redo functionality for free. Eventually, you’ll notice how other changes don’t have an affordance in the “Edit” menu. While it’s possible to get “Undo Typing” and “Undo Set Color” from some function calls, it’s not possible to get “Undo Change Text Attributes” when you use NSTextStorage.addAttributes(_:range:)
.
How to Make ReSwift Actions Undoable with NSUndoManager
I wrote about using NSUndoManager
+ ReSwift with a Middleware. You could think of the resulting UndoMiddleware
as some kind of observer of events that pass the ReSwift.Store
and which puts the opposites of incoming actions on the undo stack. Why a Middleware? Because making an action undoable is a side effect.
Putting ReSwift Actions on the Undo Stack Using Middleware
It took me a while to grok the use of “Middleware” in ReSwift. ReSwift’s own tests illustrate what you can do with it: you can filter or modify actions before they are passed to the Reducers, for example.