[LyX/master] Fix bug #12061.

Richard Kimberly Heck rikiheck at lyx.org
Mon Jan 23 22:06:13 UTC 2023


commit 62413580dee8a4ff325da8d28419b60a95cadd71
Author: Daniel Ramöller <d.lyx at web.de>
Date:   Mon Jan 23 18:05:26 2023 -0500

    Fix bug #12061.
---
 src/frontends/qt/GuiDocument.cpp  |   19 +++++++++++++++++++
 src/frontends/qt/GuiDocument.h    |    3 +++
 src/frontends/qt/ui/PreambleUi.ui |    6 +++++-
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 76b0813..287c0e8 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -481,6 +481,8 @@ PreambleModule::PreambleModule(QWidget * parent)
 	preambleTE->setFont(guiApp->typewriterSystemFont());
 	preambleTE->setWordWrapMode(QTextOption::NoWrap);
 	setFocusProxy(preambleTE);
+	// Install event filter on find line edit to capture return/enter key
+	findLE->installEventFilter(this);
 	connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
 	connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
 	connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
@@ -499,6 +501,23 @@ PreambleModule::PreambleModule(QWidget * parent)
 }
 
 
+bool PreambleModule::eventFilter(QObject * sender, QEvent * event)
+{
+	if (sender == findLE) {
+		if (event->type()==QEvent::KeyPress) {
+	        QKeyEvent * key = static_cast<QKeyEvent *>(event);
+	        if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) {
+	            findText();
+				// Return true to filter out the event
+				return true;
+	        }
+	    }
+	}
+	return QWidget::eventFilter(sender, event);
+}
+
+
+
 void PreambleModule::checkFindButton()
 {
 	findButtonPB->setEnabled(!findLE->text().isEmpty());
diff --git a/src/frontends/qt/GuiDocument.h b/src/frontends/qt/GuiDocument.h
index ef143ab..a5dfdfc 100644
--- a/src/frontends/qt/GuiDocument.h
+++ b/src/frontends/qt/GuiDocument.h
@@ -373,6 +373,9 @@ Q_SIGNALS:
 	/// signal that something's changed in the Widget.
 	void changed();
 
+protected:
+	bool eventFilter(QObject * sender, QEvent * event);
+
 private:
 	void closeEvent(QCloseEvent *) override;
 	void on_preambleTE_textChanged() { changed(); }
diff --git a/src/frontends/qt/ui/PreambleUi.ui b/src/frontends/qt/ui/PreambleUi.ui
index fd66051..eb27e91 100644
--- a/src/frontends/qt/ui/PreambleUi.ui
+++ b/src/frontends/qt/ui/PreambleUi.ui
@@ -30,7 +30,11 @@
     <number>6</number>
    </property>
    <item row="1" column="0">
-    <widget class="QLineEdit" name="findLE"/>
+    <widget class="QLineEdit" name="findLE">
+     <property name="placeholderText">
+      <string>Find in preamble</string>
+     </property>
+    </widget>
    </item>
    <item row="1" column="1">
     <widget class="QPushButton" name="findButtonPB">


More information about the lyx-cvs mailing list