Improve handling of cursor_start and cursor_end for QtConsole completions.

This partially addresses #6690.

Also, a few trailing whitespaces that my editor removed...
Argh, that's what I get for trying this from work.  Anyway, I believe this is the proper way to do it.  I'll clean this up and test it.