mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-17 19:32:30 +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):
|
def highlight_widget_selection(self, widget, startPos, endPos, clearOnFocusOut=True):
|
||||||
if isinstance(widget, QTextEdit) or isinstance(widget, QPlainTextEdit):
|
if isinstance(widget, QTextEdit) or isinstance(widget, QPlainTextEdit):
|
||||||
self._highlightTextEditSearchResult(widget, startPos, endPos, clearOnFocusOut)
|
self._highlightTextEditSearchResult(widget, startPos, endPos)
|
||||||
elif isinstance(widget, QLineEdit):
|
elif isinstance(widget, QLineEdit):
|
||||||
self._highlightLineEditSearchResult(widget, startPos, endPos, clearOnFocusOut)
|
self._highlightLineEditSearchResult(widget, startPos, endPos, clearOnFocusOut)
|
||||||
elif isinstance(widget, QTableView):
|
elif isinstance(widget, QTableView):
|
||||||
|
@ -43,22 +43,11 @@ class widgetSelectionHighlighter():
|
||||||
|
|
||||||
widget.focusOutEvent = lambda e: clearHandler(widget, widget.focusOutEvent)
|
widget.focusOutEvent = lambda e: clearHandler(widget, widget.focusOutEvent)
|
||||||
|
|
||||||
def _highlightTextEditSearchResult(self, textEdit, startPos, endPos, clearOnFocusOut):
|
def _highlightTextEditSearchResult(self, textEdit, startPos, endPos):
|
||||||
# On focus out, clear text edit selection.
|
# Highlight search result on the text edit.
|
||||||
oldTextCursor = textEdit.textCursor()
|
|
||||||
c = textEdit.textCursor()
|
c = textEdit.textCursor()
|
||||||
c.setPosition(startPos)
|
c.setPosition(startPos)
|
||||||
c.setPosition(endPos, QTextCursor.KeepAnchor)
|
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)
|
textEdit.setTextCursor(c)
|
||||||
|
|
||||||
def _highlightLineEditSearchResult(self, lineEdit, startPos, endPos, clearOnFocusOut):
|
def _highlightLineEditSearchResult(self, lineEdit, startPos, endPos, clearOnFocusOut):
|
||||||
|
|
Loading…
Reference in a new issue