--- a/src/eric7/UI/FindFileWidget.py Fri Dec 22 11:04:32 2023 +0100 +++ b/src/eric7/UI/FindFileWidget.py Fri Dec 22 13:57:47 2023 +0100 @@ -88,6 +88,7 @@ self.caseToolButton.setIcon(EricPixmapCache.getIcon("caseSensitive")) self.wordToolButton.setIcon(EricPixmapCache.getIcon("wholeWord")) + self.escapeToolButton.setIcon(EricPixmapCache.getIcon("esc-code")) self.regexpToolButton.setIcon(EricPixmapCache.getIcon("regexp")) self.dirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) @@ -346,6 +347,30 @@ if self.projectButton.isChecked(): self.dirButton.setChecked(True) + @pyqtSlot(bool) + def on_escapeToolButton_toggled(self, checked): + """ + Private slot handling a change of the escape selector. + + @param checked state of the escape selector + @type bool + """ + if checked: + # only one of regexp or escape can be selected + self.regexpToolButton.setChecked(False) + + @pyqtSlot(bool) + def on_regexpToolButton_toggled(self, checked): + """ + Private slot handling a change of the regexp selector. + + @param checked state of the regexp selector + @type bool + """ + if checked: + # only one of regexp or escape can be selected + self.escapeToolButton.setChecked(False) + @pyqtSlot(str) def on_findtextCombo_editTextChanged(self, text): """ @@ -446,7 +471,7 @@ @return text with eol stripped @rtype str """ - return txt.replace("\r", "").replace("\n", "") + return txt.rstrip("\n\r") @pyqtSlot() def __stopSearch(self): @@ -561,11 +586,13 @@ self.findProgress.setMaximum(len(files)) # retrieve the values + esc = self.escapeToolButton.isChecked() reg = self.regexpToolButton.isChecked() wo = self.wordToolButton.isChecked() cs = self.caseToolButton.isChecked() ct = self.findtextCombo.currentText() - txt = ct if reg else re.escape(ct) + txt = Utilities.unslash(ct) if esc else ct + txt = txt if reg else re.escape(txt) if wo: txt = "\\b{0}\\b".format(txt) flags = re.UNICODE @@ -608,6 +635,8 @@ Preferences.getSettings().setValue( "FindFileWidget/ReplaceHistory", self.replaceHistory[:30] ) + if esc: + replTxt = Utilities.unslash(replTxt) if self.dirButton.isChecked(): searchDir = self.dirPicker.currentText() @@ -666,13 +695,20 @@ rline = search.sub(replTxt, line) else: rline = "" - line = self.__stripEol(line) + line = Utilities.slash(line) if esc else self.__stripEol(line) if len(line) > 1024: line = "{0} ...".format(line[:1024]) if self.__replaceMode: if len(rline) > 1024: rline = "{0} ...".format(line[:1024]) - line = "- {0}\n+ {1}".format(line, self.__stripEol(rline)) + line = "- {0}\n+ {1}".format( + line, + "\n ".join( + Utilities.slash(rl) for rl in rline.splitlines(True) + ) + if esc + else self.__stripEol(rline), + ) self.__createItem(file, count, line, start, end, rline, hashStr) if time.monotonic() - now > 0.01: