tweak history prefix search (up/^p) in qtconsole

moving the cursor around the line could result in
weird inconsistencies in the prefix.

This simplifies the logic by always using the cursor position
to set the history prefix,
and better determine when the history prefix has actually changed.
fix typo in qtconsole history_next

while condition was always checking initial value,
rather than the iterating value.
check whether line was edited in qt history scroll

avoids ignoring a typed line during scrollback if the cursor is at the end of the line.
Merge pull request #2819 from minrk/qt_hist_up

tweak history prefix search (up/^p) in qtconsole

moving the cursor around the line could result in weird inconsistencies in the prefix.

This simplifies the logic by always using the cursor position to set the history prefix, and better determine when the history prefix has actually changed.

also fixes a small typo where a while-loop was always checking the initial value, rather than the iterator, which could result in an IndexError at the end of the history.

closes #2485