Improve handling of cursor_start and cursor_end for QtConsole completions.

This partially addresses #6690.

Also, a few trailing whitespaces that my editor removed...
It looks like you're carefully moving it to the end, only for the code below to immediately move it to the start. Is there a reason not to just move it to the start directly?