Changed it so that the selection rectangle cannot leave the grid.