Make cursor position calculation more generic for cursor movement code.