Fix issue with selecting a different topic when deleting a parent topic

Previously, the logic could have resulted in selecting a deleted subtopic.