Fix the logic to check if a line is selected