Just add another option to the selector, where you check for cases, where the start is before the searched date and the end is after the searched date.
$selector = "";
// Start date inside
$selector .= ", range=(";
$selector .= "datefrom>=".$input->whitelist("datefrom");
$selector .= ", datefrom<=".$input->whitelist("dateto");
$selector .= ")";
// End date inside
$selector .= ", range=(";
$selector .= "dateto>=".$input->whitelist("datefrom");
$selector .= ", dateto<=".$input->whitelist("dateto");
$selector .= ")";
// range overspans searchrange
$selector .= ", range=(";
$selector .= "dateto>=".$input->whitelist("dateto");
$selector .= ", datefrom<=".$input->whitelist("datefrom");
$selector .= ")";