Better implementation of setting current item on mouse motion in completion popups

Dont rely on the entered() signal since it is emitted even when the
mouse does not move but the list scrolls.
This commit is contained in:
Kovid Goyal 2019-11-14 15:23:39 +05:30
parent ac758eb0cd
commit 55ca95bb34
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -98,7 +98,6 @@ class Completer(QListView): # {{{
self.setAlternatingRowColors(True)
self.setModel(CompleteModel(self, sort_func=sort_func, strip_completion_entries=strip_completion_entries))
self.setMouseTracking(True)
self.entered.connect(self.item_entered, type=Qt.QueuedConnection)
self.activated.connect(self.item_chosen)
self.pressed.connect(self.item_chosen)
self.installEventFilter(self)
@ -125,16 +124,6 @@ class Completer(QListView): # {{{
if self.isVisible():
self.relayout_needed.emit()
def item_entered(self, idx):
if self.visualRect(idx).top() < self.viewport().rect().bottom() - 5:
# Prevent any bottom item in the list that is only partially
# visible from triggering setCurrentIndex()
self.entered.disconnect()
try:
self.setCurrentIndex(idx)
finally:
self.entered.connect(self.item_entered, type=Qt.QueuedConnection)
def next_match(self, previous=False):
c = self.currentIndex()
if c.isValid():
@ -206,6 +195,14 @@ class Completer(QListView): # {{{
if ev.type() in (ev.KeyPress, ev.ShortcutOverride, ev.KeyRelease):
print('\tkey:', QKeySequence(ev.key()).toString())
def mouseMoveEvent(self, ev):
idx = self.indexAt(ev.pos())
if idx.isValid():
ci = self.currentIndex()
if idx.row() != ci.row():
self.setCurrentIndex(idx)
return QListView.mouseMoveEvent(self, ev)
def eventFilter(self, obj, e):
'Redirect key presses from the popup to the widget'
widget = self.completer_widget()