Fix the UndoStack.index function

Instead of returning '-1' when the index has failed, return the value of i and a bool to indicate success. Then, rather than catching for a negative one, you can simply check against the returned bool.