Improve handling of cursor_start and cursor_end for QtConsole completions.

This partially addresses #6690.

Also, a few trailing whitespaces that my editor removed...
Going by the name, I'm not sure this is right. It looks like this will only get the current line, whereas the cursor positions in completion messages refer to a position within the entire input cell. So the problem will only show up if you have more than one line.