Fix bug #17777 with keyboard macros and visual-order cursor movement.