Fix drag selection going out of bounds (partial revert of 99f8b5f25192b8593ae337efe7f49c59ff13a3f4)