From 85816510cc345860988fb4098802757f8a75abf6 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 20 Mar 2022 22:39:19 +0200 Subject: [PATCH] - in all text editors, when writing in the Find entry, all instances of typed chars will be selected - in all text editors, pressing Enter on Find Entry will search for next instance of the searched text (no longer for focus out) --- CHANGELOG.md | 2 ++ appEditors/AppTextEditor.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e6e505d..4310c941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ CHANGELOG for FlatCAM beta - added a last resort option to load old projects; the result is not guaranteed if the differences are too great - updated the code in FlatCAMCNCJob object such that more attributes will be serialized in order for loading a project correctly when it has CNCJob objects - another fix to make the app save correctly the CNCJob objects when saving a project +- in all text editors, when writing in the Find entry, all instances of typed chars will be selected +- in all text editors, pressing Enter on Find Entry will search for next instance of the searched text (no longer for focus out) 19.03.2022 diff --git a/appEditors/AppTextEditor.py b/appEditors/AppTextEditor.py index d30de3ab..c5f1b598 100644 --- a/appEditors/AppTextEditor.py +++ b/appEditors/AppTextEditor.py @@ -165,8 +165,11 @@ class AppTextEditor(QtWidgets.QWidget): self.buttonPrint.clicked.connect(self.handlePrint) self.buttonPreview.clicked.connect(self.handlePreview) self.buttonFind.clicked.connect(self.handleFindGCode) - self.entryFind.editingFinished.connect(self.handleFindGCode) + self.entryFind.returnPressed.connect(self.handleFindGCode) self.buttonReplace.clicked.connect(self.handleReplaceGCode) + + self.entryFind.textChanged.connect(self.on_text_changed) + # self.button_copy_all.clicked.connect(self.handleCopyAll) self.code_editor.set_model_data(self.app.myKeywords) @@ -350,7 +353,7 @@ class AppTextEditor(QtWidgets.QWidget): bt_ok = msgbox.addButton(_('Ok'), QtWidgets.QMessageBox.ButtonRole.AcceptRole) bt_cancel = msgbox.addButton(_('Cancel'), QtWidgets.QMessageBox.ButtonRole.RejectRole) - msgbox.setDefaultButton(bt_cancel) + msgbox.setDefaultButton(bt_ok) msgbox.exec() response = msgbox.clickedButton() @@ -388,6 +391,22 @@ class AppTextEditor(QtWidgets.QWidget): # Mark end of undo block cursor.endEditBlock() + def on_text_changed(self, txt): + extra_sel_list = [] + flags = QtGui.QTextDocument.FindFlag.FindCaseSensitively + self.code_editor.moveCursor(QtGui.QTextCursor.MoveOperation.Start) + + while self.code_editor.find(str(txt), flags): + extra_sel = QtWidgets.QTextEdit.ExtraSelection() + extra_sel.cursor = self.code_editor.textCursor() + fmt = QtGui.QTextCharFormat() + fmt.setBackground(QtCore.Qt.GlobalColor.yellow) + extra_sel.format = fmt + extra_sel_list.append(extra_sel) + + self.code_editor.moveCursor(QtGui.QTextCursor.MoveOperation.Start) + self.code_editor.setExtraSelections(extra_sel_list) + # def handleCopyAll(self): # text = self.code_editor.toPlainText() # self.app.clipboard.setText(text)