fix KeyPress coordinates
@@ -105,7 +105,6 @@ class CompletionWidget(QtWidgets.QListWidget):
""" Shows the completion widget with 'items' at the position specified
by 'cursor'.
"""
- text_edit = self._text_edit
point = self._get_top_left_position(cursor)
self.clear()
path_items = []
@@ -140,7 +139,7 @@ class CompletionWidget(QtWidgets.QListWidget):
screen_height = screen_rect.height()
height = int(min(self._height_max, screen_height - 50)) # -50px
if ((screen_height - point.y() - height) < 0):
- point = text_edit.mapToGlobal(text_edit.cursorRect().topRight())
+ point = self._text_edit.mapToGlobal(self._text_edit.cursorRect().topRight())
py = point.y()
point.setY(int(py - min(height, py - 10))) # -10px
w = (self.sizeHintForColumn(0) +
@@ -163,20 +162,7 @@ class CompletionWidget(QtWidgets.QListWidget):
def _get_top_left_position(self, cursor):
""" Get top left position for this widget.
"""
- point = self._text_edit.cursorRect(cursor).center()
- point_size = self._text_edit.font().pointSize()
-
- if sys.platform == 'darwin':
- delta = int((point_size * 1.20) ** 0.98)
- elif os.name == 'nt':
- delta = int((point_size * 1.20) ** 1.05)
- else:
- delta = int((point_size * 1.20) ** 0.98)
-
- y = delta - (point_size / 2)
- point.setY(int(point.y() + y))
- point = self._text_edit.mapToGlobal(point)
- return point
+ return self._text_edit.mapToGlobal(self._text_edit.cursorRect().bottomRight())
def _complete_current(self):
""" Perform the completion with the currently selected item.
@@ -202,6 +188,7 @@ class CompletionWidget(QtWidgets.QListWidget):
# Update widget position
cursor = self._text_edit.textCursor()
point = self._get_top_left_position(cursor)
+ point.setY(self.y())
self.move(point)
# Update current item
