Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use QRegularExpression for find and replace (in Pyqt5).
Browse files Browse the repository at this point in the history
This change allows the use of lazy regular expresions
rlaverde committed Nov 17, 2016
1 parent 58c744f commit 987074c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
@@ -19,10 +19,17 @@
import textwrap

# Third party imports
from qtpy.QtCore import QPoint, QRegExp, Qt
from qtpy.QtCore import QPoint, Qt
from qtpy.QtGui import QCursor, QTextCursor, QTextDocument
from qtpy.QtWidgets import QApplication, QToolTip

from qtpy import PYQT5, PYQT4

if PYQT5:
from qtpy.QtCore import QRegularExpression
elif PYQT4:
from qtpy.QtCore import QRegExp

# Local imports
from spyder.config.base import _
from spyder.py3compat import is_text_string, to_text_string, u
@@ -480,9 +487,14 @@ def find_text(self, text, changed=True, forward=True, case=False,
moves += [QTextCursor.End]
if not regexp:
text = re.escape(to_text_string(text))
pattern = QRegExp(r"\b%s\b" % text if words else text,
Qt.CaseSensitive if case else Qt.CaseInsensitive,
QRegExp.RegExp2)
if PYQT5:
pattern = QRegularExpression(r"\b%s\b" % text if words else text)
if case:
pattern.setPatternOptions(QRegularExpression.CaseInsensitiveOption)
elif PYQT4:
pattern = QRegExp(r"\b%s\b" % text if words else text,
Qt.CaseSensitive if case else Qt.CaseInsensitive,
QRegExp.RegExp2)
for move in moves:
cursor.movePosition(move)
if regexp and '\\n' in text:

0 comments on commit 987074c

Please sign in to comment.