hasSelection = selection.length > 0;
would be more efficent