Save and restore selection state.