@@ -1006,7 +1006,6 @@ def _append_custom(self, insert, input, before_prompt=False, *args, **kwargs):
1006
1006
else :
1007
1007
if insert != self ._insert_plain_text :
1008
1008
self ._flush_pending_stream ()
1009
- cursor .movePosition (QtGui .QTextCursor .End )
1010
1009
1011
1010
# Perform the insertion.
1012
1011
result = insert (cursor , input , * args , ** kwargs )
@@ -1660,10 +1659,7 @@ def _on_flush_pending_stream_timer(self):
1660
1659
""" Flush the pending stream output and change the
1661
1660
prompt position appropriately.
1662
1661
"""
1663
- cursor = self ._control .textCursor ()
1664
- cursor .movePosition (QtGui .QTextCursor .End )
1665
1662
self ._flush_pending_stream ()
1666
- cursor .movePosition (QtGui .QTextCursor .End )
1667
1663
1668
1664
def _flush_pending_stream (self ):
1669
1665
""" Flush out pending text into the widget. """
@@ -1674,7 +1670,7 @@ def _flush_pending_stream(self):
1674
1670
text = self ._get_last_lines_from_list (text , buffer_size )
1675
1671
text = '' .join (text )
1676
1672
t = time .time ()
1677
- self ._insert_plain_text (self ._get_end_cursor (), text , flush = True )
1673
+ self ._insert_plain_text (self ._control . textCursor (), text , flush = True )
1678
1674
# Set the flush interval to equal the maximum time to update text.
1679
1675
self ._pending_text_flush_interval .setInterval (
1680
1676
int (max (100 , (time .time () - t ) * 1000 ))
@@ -2086,6 +2082,9 @@ def _insert_plain_text(self, cursor, text, flush=False):
2086
2082
""" Inserts plain text using the specified cursor, processing ANSI codes
2087
2083
if enabled.
2088
2084
"""
2085
+ if not text and not flush :
2086
+ return
2087
+
2089
2088
should_autoscroll = self ._viewport_at_end ()
2090
2089
# maximumBlockCount() can be different from self.buffer_size in
2091
2090
# case input prompt is active.
@@ -2123,7 +2122,7 @@ def _insert_plain_text(self, cursor, text, flush=False):
2123
2122
cursor .select (QtGui .QTextCursor .Document )
2124
2123
remove = True
2125
2124
if act .area == 'line' :
2126
- if act .erase_to == 'all' :
2125
+ if act .erase_to == 'all' :
2127
2126
cursor .select (QtGui .QTextCursor .LineUnderCursor )
2128
2127
remove = True
2129
2128
elif act .erase_to == 'start' :
@@ -2137,7 +2136,7 @@ def _insert_plain_text(self, cursor, text, flush=False):
2137
2136
QtGui .QTextCursor .EndOfLine ,
2138
2137
QtGui .QTextCursor .KeepAnchor )
2139
2138
remove = True
2140
- if remove :
2139
+ if remove :
2141
2140
nspace = cursor .selectionEnd ()- cursor .selectionStart () if fill else 0
2142
2141
cursor .removeSelectedText ()
2143
2142
if nspace > 0 : cursor .insertText (' ' * nspace ) # replace text by space, to keep cursor position as specified
@@ -2181,11 +2180,12 @@ def _insert_plain_text(self, cursor, text, flush=False):
2181
2180
remain = cursor2 .position () - pos # number of characters until end of line
2182
2181
n = len (substring )
2183
2182
swallow = min (n , remain ) # number of character to swallow
2184
- cursor .setPosition (pos + swallow ,QtGui .QTextCursor .KeepAnchor )
2183
+ cursor .setPosition (pos + swallow , QtGui .QTextCursor .KeepAnchor )
2185
2184
cursor .insertText (substring ,format )
2186
2185
else :
2187
2186
cursor .insertText (text )
2188
2187
cursor .endEditBlock ()
2188
+ self ._control .setTextCursor (cursor )
2189
2189
2190
2190
if should_autoscroll :
2191
2191
self ._scroll_to_end ()
0 commit comments