Fix potential infinite loop for selection change events