clear selection event queue before emitting event

Clear the event queue before the selection event is fired to prevent
recursing if an event handler also triggers a selection event
Add test case for selection event recursion issue