eric7/EricWidgets/EricTextEditSearchWidget.py

branch
eric7
changeset 8706
16b25e115ac0
parent 8702
131ef7267fd4
child 8739
55e07d9608f0
--- a/eric7/EricWidgets/EricTextEditSearchWidget.py	Wed Oct 20 19:47:18 2021 +0200
+++ b/eric7/EricWidgets/EricTextEditSearchWidget.py	Wed Oct 20 19:48:21 2021 +0200
@@ -226,6 +226,7 @@
         self.wordCheckBox.setVisible(editType in (
             EricTextEditType.QTEXTEDIT, EricTextEditType.QTEXTBROWSER
         ))
+        self.infoLabel.setVisible(editType == EricTextEditType.QWEBENGINEVIEW)
         if editType == EricTextEditType.QWEBENGINEVIEW:
             self.__textedit.page().findTextFinished.connect(
                 self.__findTextFinished)
@@ -306,7 +307,10 @@
         """
         self.__setSearchButtons(txt != "")
         
-        self.infoLabel.hide()
+        if self.__texteditType == EricTextEditType.QWEBENGINEVIEW:
+            self.infoLabel.clear()
+        else:
+            self.infoLabel.hide()
         self.__setFindtextComboBackground(False)
     
     def __setSearchButtons(self, enabled):
@@ -365,7 +369,8 @@
             return
         
         self.infoLabel.clear()
-        self.infoLabel.hide()
+        if self.__texteditType != EricTextEditType.QWEBENGINEVIEW:
+            self.infoLabel.hide()
         self.__setFindtextComboBackground(False)
         
         txt = self.findtextCombo.currentText()
@@ -384,8 +389,7 @@
         if self.__texteditType in (
             EricTextEditType.QTEXTBROWSER, EricTextEditType.QTEXTEDIT
         ):
-            ok = self.__findPrevNextQTextEdit(backwards)
-            self.__findNextPrevCallback(ok)
+            self.__findPrevNextQTextEdit(backwards)
         elif self.__texteditType == EricTextEditType.QWEBENGINEVIEW:
             self.__findPrevNextQWebEngineView(backwards)
     
@@ -423,7 +427,13 @@
             self.__textedit.setTextCursor(cursor)
             ok = self.__textedit.find(self.findtextCombo.currentText(), flags)
         
-        return ok
+        if not ok:
+            self.infoLabel.setText(
+                self.tr("'{0}' was not found.").format(
+                    self.findtextCombo.currentText())
+            )
+            self.infoLabel.show()
+            self.__setFindtextComboBackground(True)
     
     def __findPrevNextQWebEngineView(self, backwards):
         """
@@ -440,22 +450,7 @@
             findFlags |= QWebEnginePage.FindFlag.FindCaseSensitively
         if backwards:
             findFlags |= QWebEnginePage.FindFlag.FindBackward
-        self.__textedit.findText(self.findtextCombo.currentText(),
-                                 findFlags, self.__findNextPrevCallback)
-    
-    def __findNextPrevCallback(self, found):
-        """
-        Private method to process the result of the last search.
-        
-        @param found flag indicating if the last search succeeded
-        @type bool
-        """
-        if not found:
-            txt = self.findtextCombo.currentText()
-            self.infoLabel.setText(
-                self.tr("'{0}' was not found.").format(txt))
-            self.infoLabel.show()
-            self.__setFindtextComboBackground(True)
+        self.__textedit.findText(self.findtextCombo.currentText(), findFlags)
     
     def __setFindtextComboBackground(self, error):
         """
@@ -484,10 +479,16 @@
             last search
         @type QWebEngineFindTextResult
         """
-        self.infoLabel.setText(self.tr("Match {0} of {1}").format(
-            result.activeMatch(), result.numberOfMatches())
-        )
-        self.infoLabel.show()
+        if result.numberOfMatches() == 0:
+            self.infoLabel.setText(
+                self.tr("'{0}' was not found.").format(
+                    self.findtextCombo.currentText())
+            )
+            self.__setFindtextComboBackground(True)
+        else:
+            self.infoLabel.setText(self.tr("Match {0} of {1}").format(
+                result.activeMatch(), result.numberOfMatches())
+            )
     
     def showInfo(self, info):
         """

eric ide

mercurial