Add beforeSelectionChange event

Issue #1262