Clear selection on undo/redo to avoid potential crashes