Remove clearing focus in text edits to prevent a jumping cursor when not intended

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2023-02-01 21:15:13 +01:00
parent 380354bdf8
commit 7293db7c40
No known key found for this signature in database
GPG key ID: D850A5F772E880F9

View file

@ -14,7 +14,7 @@ class widgetSelectionHighlighter():
def highlight_widget_selection(self, widget, startPos, endPos, clearOnFocusOut=True):
if isinstance(widget, QTextEdit) or isinstance(widget, QPlainTextEdit):
self._highlightTextEditSearchResult(widget, startPos, endPos, clearOnFocusOut)
self._highlightTextEditSearchResult(widget, startPos, endPos)
elif isinstance(widget, QLineEdit):
self._highlightLineEditSearchResult(widget, startPos, endPos, clearOnFocusOut)
elif isinstance(widget, QTableView):
@ -43,22 +43,11 @@ class widgetSelectionHighlighter():
widget.focusOutEvent = lambda e: clearHandler(widget, widget.focusOutEvent)
def _highlightTextEditSearchResult(self, textEdit, startPos, endPos, clearOnFocusOut):
# On focus out, clear text edit selection.
oldTextCursor = textEdit.textCursor()
def _highlightTextEditSearchResult(self, textEdit, startPos, endPos):
# Highlight search result on the text edit.
c = textEdit.textCursor()
c.setPosition(startPos)
c.setPosition(endPos, QTextCursor.KeepAnchor)
if clearOnFocusOut:
def clearSelection(widget):
cur = widget.textCursor()
if cur.hasSelection() and cur.anchor() == startPos and cur.position() == endPos:
widget.setTextCursor(oldTextCursor)
self.generateClearHandler(textEdit, clearSelection)
# Highlight search result on the text edit.
textEdit.setTextCursor(c)
def _highlightLineEditSearchResult(self, lineEdit, startPos, endPos, clearOnFocusOut):