Skip to content

Commit

Permalink
Merge 096d859 into 9caa81a
Browse files Browse the repository at this point in the history
  • Loading branch information
impact27 committed Sep 9, 2019
2 parents 9caa81a + 096d859 commit 4cef3ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 20 additions & 7 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def __init__(self, parent=None, **kw):
self.setParent(parent)

self._is_complete_msg_id = None
self._is_complete_timeout = 0.25
self._is_complete_max_time = None
self._is_complete_number_returns = 0

# While scrolling the pager on Mac OS X, it tears badly. The
# NativeGesture is platform and perhaps build-specific hence
Expand Down Expand Up @@ -409,7 +412,6 @@ def eventFilter(self, obj, event):
text widgets.
"""
etype = event.type()
self._trigger_is_complete_callback()
if etype == QtCore.QEvent.KeyPress:

# Re-map keys for all filtered widgets.
Expand Down Expand Up @@ -583,11 +585,20 @@ def _trigger_is_complete_callback(self, complete=False, indent=u''):
if self._is_complete_msg_id is not None:
self._is_complete_msg_id = None
self._is_complete_callback(complete, indent)
self._is_complete_number_returns = 0

def _register_is_complete_callback(self, source, callback):
self._trigger_is_complete_callback()
self._is_complete_msg_id = self.kernel_client.is_complete(source)
self._is_complete_number_returns += 1
if self._is_complete_msg_id is not None:
if self._is_complete_max_time < time.time():
# Second return while waiting for is_complete
return
else:
# request timed out
self._trigger_is_complete_callback()
self._is_complete_max_time = time.time() + self._is_complete_timeout
self._is_complete_callback = callback
self._is_complete_msg_id = self.kernel_client.is_complete(source)

def execute(self, source=None, hidden=False, interactive=False):
""" Executes source or the input buffer, possibly prompting for more
Expand Down Expand Up @@ -1231,10 +1242,11 @@ def callback(complete, indent):
try:
cursor.beginEditBlock()
cursor.setPosition(position)
cursor.insertText('\n')
self._insert_continuation_prompt(cursor)
if indent:
cursor.insertText(indent)
for i in range(self._is_complete_number_returns):
cursor.insertText('\n')
self._insert_continuation_prompt(cursor)
if indent:
cursor.insertText(indent)
finally:
cursor.endEditBlock()

Expand Down Expand Up @@ -1368,6 +1380,7 @@ def callback(complete, indent):
#------ No modifiers ---------------------------------------------------

else:
self._trigger_is_complete_callback()
if shift_down:
anchormode = QtGui.QTextCursor.KeepAnchor
else:
Expand Down
3 changes: 1 addition & 2 deletions qtconsole/tests/test_00_console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ def is_complete(self, source):
self.assertEqual(calls, ["done"])
calls = []
self.assert_text_equal(cursor, u"thing\u2029> !!!else\u2029")
event = QtCore.QEvent(QtCore.QEvent.User)
w.eventFilter(w, event)
w._trigger_is_complete_callback()
self.assert_text_equal(cursor, u"thing\u2029> !!!else\u2029\u2029> ")

# assert that late answer isn't destroying anything
Expand Down

0 comments on commit 4cef3ea

Please sign in to comment.