Fix handling of cursor offset and handle end <= start.