Improve handling of cursor_start and cursor_end for completions.

Improve handling of cursor_start and cursor_end for completions.

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.

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

Reinstate extra whitespace

More whitespace reinstating

Still more whitespace

Finalwhitespace

Add a guard on start

Fix logic for end > cursor_pos

Another ws add

WS tweak

WS again
Add comments
Merge pull request #6692 from blink1073/qtconsole-completion

Improve handling of cursor_start and cursor_end for QtConsole completions.