Does this case only happen when the very first move at the beginning of the function (on line 330) goes past the end of the selection? If so, seems like we ought to detect it up there instead of here.