@@ -297,6 +297,10 @@ def __init__(self, parent=None, **kw):
297
297
self ._reading_callback = None
298
298
self ._tab_width = 4
299
299
300
+ # Cursor position of where to insert text.
301
+ # Control characters allow this to move around on the current line.
302
+ self ._insert_text_cursor = self ._control .textCursor ()
303
+
300
304
# List of strings pending to be appended as plain text in the widget.
301
305
# The text is not immediately inserted when available to not
302
306
# choke the Qt event loop with paint events for the widget in
@@ -695,6 +699,9 @@ def do_execute(self, source, complete, indent):
695
699
# effect when using a QTextEdit. I believe this is a Qt bug.
696
700
self ._control .moveCursor (QtGui .QTextCursor .End )
697
701
702
+ # Advance where text is inserted
703
+ self ._insert_text_cursor .movePosition (QtGui .QTextCursor .End )
704
+
698
705
def export_html (self ):
699
706
""" Shows a dialog to export HTML/XML in various formats.
700
707
"""
@@ -712,6 +719,9 @@ def _finalize_input_request(self):
712
719
self ._append_before_prompt_cursor .setPosition (
713
720
self ._get_end_cursor ().position ())
714
721
722
+ self ._insert_text_cursor .setPosition (
723
+ self ._get_end_cursor ().position ())
724
+
715
725
# The maximum block count is only in effect during execution.
716
726
# This ensures that _prompt_pos does not become invalid due to
717
727
# text truncation.
@@ -998,7 +1008,7 @@ def _append_custom(self, insert, input, before_prompt=False, *args, **kwargs):
998
1008
current prompt, if there is one.
999
1009
"""
1000
1010
# Determine where to insert the content.
1001
- cursor = self ._control . textCursor ()
1011
+ cursor = self ._insert_text_cursor
1002
1012
if before_prompt and (self ._reading or not self ._executing ):
1003
1013
self ._flush_pending_stream ()
1004
1014
cursor ._insert_mode = True
@@ -1009,6 +1019,11 @@ def _append_custom(self, insert, input, before_prompt=False, *args, **kwargs):
1009
1019
1010
1020
# Perform the insertion.
1011
1021
result = insert (cursor , input , * args , ** kwargs )
1022
+
1023
+ # Remove insert mode tag
1024
+ if hasattr (cursor , "_insert_mode" ):
1025
+ del cursor ._insert_mode
1026
+
1012
1027
return result
1013
1028
1014
1029
def _append_block (self , block_format = None , before_prompt = False ):
@@ -1670,7 +1685,7 @@ def _flush_pending_stream(self):
1670
1685
text = self ._get_last_lines_from_list (text , buffer_size )
1671
1686
text = '' .join (text )
1672
1687
t = time .time ()
1673
- self ._insert_plain_text (self ._control . textCursor () , text , flush = True )
1688
+ self ._insert_plain_text (self ._insert_text_cursor , text , flush = True )
1674
1689
# Set the flush interval to equal the maximum time to update text.
1675
1690
self ._pending_text_flush_interval .setInterval (
1676
1691
int (max (100 , (time .time () - t ) * 1000 ))
@@ -2182,7 +2197,6 @@ def _insert_plain_text(self, cursor, text, flush=False):
2182
2197
else :
2183
2198
cursor .insertText (text )
2184
2199
cursor .endEditBlock ()
2185
- self ._control .setTextCursor (cursor )
2186
2200
2187
2201
if should_autoscroll :
2188
2202
self ._scroll_to_end ()
0 commit comments