mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-15 01:14:34 +12:00
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:
parent
380354bdf8
commit
7293db7c40
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue