Improve handling of cursor_start and cursor_end for completions.
Fix handling of end != cursor_position
Fix handling of cursor offset and handle end <= start.