Undo not working when painting with terrain brush

If I have a terrain bush and I paint on an empty layer, it work 100% fine, but I am unable to undo the changes. If I paint with a terrain brush over existing tiles, undo work fine.

To reproduce, create an empty map, then paint with the terrain brush over empty tiles. The tiles are painted, but undo doesn’t work.

Please remember to also mention the version of Tiled you’re reporting the problem against. I found that this works fine in Tiled 1.2.4 but is broken in the latest snapshot.

It seems that it broke in this recent change, but it’s not immediately obvious to me why. I’ll dig into it soon. Thanks for the report!

The following change takes care of this problem, hopefully without introducing new ones elsewhere:

Thanks for the fix!