Generalized moving cursor positioning code