From a2b2910bd76be161312cba355d7c730fb5e7b617 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 3 Jul 2020 23:06:56 +0200 Subject: [PATCH] If running with Qt 5.13 or higher, search/replace uses the QRegularExpression class instead of just QRegExp --- nw/gui/doceditor.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index c51049c6..97189307 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -35,7 +35,9 @@ import nw from time import time -from PyQt5.QtCore import Qt, QSize, QThread, QTimer, pyqtSlot, QRegExp +from PyQt5.QtCore import ( + Qt, QSize, QThread, QTimer, pyqtSlot, QRegExp, QRegularExpression +) from PyQt5.QtGui import ( QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QIcon, QTextDocument, QCursor, QPixmap @@ -1517,14 +1519,26 @@ class GuiDocEditSearch(QFrame): expression object. """ theText = self.searchBox.text() - if self.isRegEx and self.mainConf.verQtValue >= 50300: - if self.isCaseSense: - rxCase = Qt.CaseSensitive - else: - rxCase = Qt.CaseInsensitive - theRegEx = QRegExp(theText, rxCase) - self._alertSearchValid(theRegEx.isValid()) - return theRegEx + if self.isRegEx: + # Using the Unicode-capable QRegularExpression class was + # only added in Qt 5.13. Otherwise, 5.3 and up supports + # only the QRegExp class. + if self.mainConf.verQtValue >= 51300: + rxOpt = QRegularExpression.UseUnicodePropertiesOption + if not self.isCaseSense: + rxOpt |= QRegularExpression.CaseInsensitiveOption + theRegEx = QRegularExpression(theText, rxOpt) + self._alertSearchValid(theRegEx.isValid()) + return theRegEx + + elif self.mainConf.verQtValue >= 50300: + if self.isCaseSense: + rxOpt = Qt.CaseSensitive + else: + rxOpt = Qt.CaseInsensitive + theRegEx = QRegExp(theText, rxOpt) + self._alertSearchValid(theRegEx.isValid()) + return theRegEx return theText