Skip to content

Commit

Permalink
Merge 13f042d into 0f30332
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Jun 28, 2019
2 parents 0f30332 + 13f042d commit c8560d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 15 additions & 3 deletions qtconsole/completion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, console_widget):
"""
text_edit = console_widget._control
assert isinstance(text_edit, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
super(CompletionWidget, self).__init__()
super(CompletionWidget, self).__init__(parent=console_widget)

self._text_edit = text_edit
self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
Expand Down Expand Up @@ -94,7 +94,7 @@ def showEvent(self, event):
# 'CompletionWidget' interface
#--------------------------------------------------------------------------

def show_items(self, cursor, items):
def show_items(self, cursor, items, prefix_length=0):
""" Shows the completion widget with 'items' at the position specified
by 'cursor'.
"""
Expand All @@ -112,6 +112,10 @@ def show_items(self, cursor, items):
w = (self.sizeHintForColumn(0) +
self.verticalScrollBar().sizeHint().width())
self.setGeometry(point.x(), point.y(), w, height)

# Move cursor to start of the prefix to replace it
# when a item is selected
cursor.movePosition(QtGui.QTextCursor.Left, n=prefix_length)
self._start_position = cursor.position()
self.setCurrentRow(0)
self.raise_()
Expand All @@ -138,8 +142,16 @@ def _current_text_cursor(self):
return cursor

def _update_current(self):
""" Updates the current item based on the current text.
""" Updates the current item based on the current text and the
position of the widget.
"""
# Update widget position
cursor = self._text_edit.textCursor()
point = self._text_edit.cursorRect(cursor).bottomRight()
position = self._text_edit.mapToGlobal(point)
self.move(position)

# Update current item
prefix = self._current_text_cursor().selection().toPlainText()
if prefix:
items = self.findItems(prefix, (QtCore.Qt.MatchStartsWith |
Expand Down
5 changes: 2 additions & 3 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,8 @@ def _complete_with_items(self, cursor, items):
cursor.insertText(prefix)
current_pos = cursor.position()

cursor.movePosition(QtGui.QTextCursor.Left, n=len(prefix))
self._completion_widget.show_items(cursor, items)

self._completion_widget.show_items(cursor, items,
prefix_length=len(prefix))

def _fill_temporary_buffer(self, cursor, text, html=False):
"""fill the area below the active editting zone with text"""
Expand Down

0 comments on commit c8560d2

Please sign in to comment.