Skip to content

Commit 7289b62

Browse files
committed
Add error() possibility to app.transaction() callback
From https://community.aseprite.org/t/cancel-a-transaction/24406 and aseprite/aseprite#4946
1 parent 370652e commit 7289b62

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

api/app.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,32 @@ app.transaction(
181181
```
182182

183183
Creates a new transaction so you can group several sprite
184-
modifications in just one undo/redo operation.
184+
modifications in just one undo/redo operation. If a string is given as
185+
first argument, that string will be used as the label of this
186+
undo/redo action (which can be seen in the *Edit > Undo History*
187+
window).
185188

186-
The function in the argument is called inside the transaction, if the
187-
function fails, the whole transaction is undone. If the function
188-
successes, the transaction is committed and then all actions will be
189-
grouped in just one undo/redo operation.
189+
The given function is called inside the transaction, if the function
190+
fails, the whole transaction is undone (i.e. all the steps executed so
191+
far will be reversed). If the function successes, the transaction is
192+
committed and then all actions will be grouped in just one undo/redo
193+
operation.
190194

191-
If a string is given as first argument, that string will be used as a
192-
label for the undo/redo action.
195+
You can cancel/reverse/cause an explicit failure of the transaction
196+
calling the `error()` Lua function, e.g:
197+
198+
```lua
199+
app.transaction(
200+
function()
201+
...
202+
if something_is_wrong then
203+
error() -- this stops the function and doesn't continue with the
204+
-- following lines / the actions so far will be reversed
205+
-- automatically leaving the sprite intact
206+
end
207+
...
208+
end)
209+
```
193210

194211
## app.command
195212

0 commit comments

Comments
 (0)