Fix endless loop when repeating i' or a'.

Since selection wouldn't change, the "selection extension" code would
go in an endless loop.

Add a loop limit as a stopgap solution.