diff -r 9eed155411f0 -r 4a1db75550bd eric6/WebBrowser/History/HistoryCompleter.py --- a/eric6/WebBrowser/History/HistoryCompleter.py Sat Oct 10 16:03:53 2020 +0200 +++ b/eric6/WebBrowser/History/HistoryCompleter.py Sun Oct 11 17:54:52 2020 +0200 @@ -7,8 +7,9 @@ Module implementing a special completer for the history. """ +import re -from PyQt5.QtCore import Qt, QRegExp, QTimer, QSortFilterProxyModel +from PyQt5.QtCore import Qt, QTimer, QSortFilterProxyModel from PyQt5.QtWidgets import QTableView, QAbstractItemView, QCompleter from .HistoryModel import HistoryModel @@ -76,9 +77,8 @@ super(HistoryCompletionModel, self).__init__(parent) self.__searchString = "" - self.__searchMatcher = QRegExp( - "", Qt.CaseInsensitive, QRegExp.FixedString) - self.__wordMatcher = QRegExp("", Qt.CaseInsensitive) + self.__searchMatcher = None + self.__wordMatcher = None self.__isValid = False self.setDynamicSortFilter(True) @@ -115,20 +115,19 @@ """ return self.__searchString - def setSearchString(self, string): + def setSearchString(self, sstring): """ Public method to set the current search string. - @param string new search string (string) + @param sstring new search string (string) """ - if string == self.__searchString: - return - - self.__searchString = string - self.__searchMatcher.setPattern(self.__searchString) - self.__wordMatcher.setPattern( - "\\b" + QRegExp.escape(self.__searchString)) - self.invalidateFilter() + if sstring != self.__searchString: + self.__searchString = sstring + self.__searchMatcher = re.compile( + re.escape(self.__searchString), re.IGNORECASE) + self.__wordMatcher = re.compile( + r"\b" + re.escape(self.__searchString), re.IGNORECASE) + self.invalidateFilter() def isValid(self): """ @@ -161,18 +160,19 @@ @param sourceParent index of the source item (QModelIndex) @return flag indicating acceptance (boolean) """ - # Do a case-insensitive substring match against both the url and title. - # It's already ensured, that the user doesn't accidentally use regexp - # metacharacters (s. setSearchString()). - idx = self.sourceModel().index(sourceRow, 0, sourceParent) - - url = self.sourceModel().data(idx, HistoryModel.UrlStringRole) - if self.__searchMatcher.indexIn(url) != -1: - return True - - title = self.sourceModel().data(idx, HistoryModel.TitleRole) - if self.__searchMatcher.indexIn(title) != -1: - return True + if self.__searchMatcher is not None: + # Do a case-insensitive substring match against both the url and + # title. It's already ensured, that the user doesn't accidentally + # use regexp metacharacters (s. setSearchString()). + idx = self.sourceModel().index(sourceRow, 0, sourceParent) + + url = self.sourceModel().data(idx, HistoryModel.UrlStringRole) + if self.__searchMatcher.search(url) is not None: + return True + + title = self.sourceModel().data(idx, HistoryModel.TitleRole) + if self.__searchMatcher.search(title) is not None: + return True return False @@ -188,9 +188,12 @@ "www.phoronix.com" a bonus for "ph", it does NOT make sense to give "www.yadda.com/foo.php" the bonus. - @param left index of left item (QModelIndex) - @param right index of right item (QModelIndex) - @return true, if left is less than right (boolean) + @param left index of left item + @type QModelIndex + @param right index of right item + @type QModelIndex + @return true, if left is less than right + @rtype bool """ frequency_L = self.sourceModel().data( left, HistoryFilterModel.FrequencyRole) @@ -198,8 +201,9 @@ title_L = self.sourceModel().data(left, HistoryModel.TitleRole) if ( - self.__wordMatcher.indexIn(url_L) != -1 or - self.__wordMatcher.indexIn(title_L) != -1 + self.__wordMatcher is not None and + (bool(self.__wordMatcher.search(url_L)) or + bool(self.__wordMatcher.search(title_L))) ): frequency_L *= 2 @@ -209,8 +213,9 @@ title_R = self.sourceModel().data(right, HistoryModel.TitleRole) if ( - self.__wordMatcher.indexIn(url_R) != -1 or - self.__wordMatcher.indexIn(title_R) != -1 + self.__wordMatcher is not None and + (bool(self.__wordMatcher.search(url_R)) or + bool(self.__wordMatcher.search(title_R))) ): frequency_R *= 2