[LyX/master] GuiSearch: catch global shortcuts to find forwards/backwards (#11170)

Juergen Spitzmueller spitz at lyx.org
Fri Feb 12 09:48:51 UTC 2021


commit d1ea8a40afc54edb37965c632b261b1f2cfe2fad
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Fri Feb 12 10:50:47 2021 +0100

    GuiSearch: catch global shortcuts to find forwards/backwards (#11170)
---
 src/frontends/qt/GuiSearch.cpp |   32 ++++++++++++++++++++++++++++++--
 src/frontends/qt/GuiSearch.h   |    5 ++++-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index 3bd1be0..e33e421 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -20,6 +20,9 @@
 #include "BufferView.h"
 #include "Buffer.h"
 #include "Cursor.h"
+#include "FuncRequest.h"
+#include "KeyMap.h"
+#include "GuiKeySymbol.h"
 #include "GuiView.h"
 
 #include "support/gettext.h"
@@ -30,6 +33,8 @@
 
 using namespace std;
 
+using lyx::KeySymbol;
+
 namespace lyx {
 namespace frontend {
 
@@ -75,6 +80,29 @@ GuiSearch::GuiSearch(GuiView & lv)
 }
 
 
+void GuiSearch::keyPressEvent(QKeyEvent * ev)
+{
+	KeySymbol sym;
+	setKeySymbol(&sym, ev);
+
+	// we catch the key sequences for forward and backwards search
+	if (sym.isOK()) {
+		KeyModifier mod = lyx::q_key_state(ev->modifiers());
+		KeySequence keyseq(&theTopLevelKeymap(), &theTopLevelKeymap());
+		FuncRequest fr = keyseq.addkey(sym, mod);
+		if (fr == FuncRequest(LFUN_WORD_FIND_FORWARD) || fr == FuncRequest(LFUN_WORD_FIND)) {
+			findClicked();
+			return;
+		}
+		if (fr == FuncRequest(LFUN_WORD_FIND_BACKWARD)) {
+			findClicked(true);
+			return;
+		}
+	}
+	QDialog::keyPressEvent(ev);
+}
+
+
 void GuiSearch::showEvent(QShowEvent * e)
 {
 	findChanged();
@@ -95,11 +123,11 @@ void GuiSearch::findChanged()
 }
 
 
-void GuiSearch::findClicked()
+void GuiSearch::findClicked(bool const backwards)
 {
 	docstring const needle = qstring_to_ucs4(findCO->currentText());
 	find(needle, caseCB->isChecked(), wordsCB->isChecked(),
-		!backwardsCB->isChecked());
+		(!backwards && !backwardsCB->isChecked()));
 	uniqueInsert(findCO, findCO->currentText());
 	findCO->lineEdit()->selectAll();
 }
diff --git a/src/frontends/qt/GuiSearch.h b/src/frontends/qt/GuiSearch.h
index 2901110..e6c7c99 100644
--- a/src/frontends/qt/GuiSearch.h
+++ b/src/frontends/qt/GuiSearch.h
@@ -28,11 +28,14 @@ public:
 
 private Q_SLOTS:
 	void findChanged();
-	void findClicked();
+	void findClicked(bool const backwards = false);
 	void replaceClicked();
 	void replaceallClicked();
 
 private:
+	///
+	void keyPressEvent(QKeyEvent * e) override;
+	///
 	void showEvent(QShowEvent * e) override;
 	///
 	bool initialiseParams(std::string const &) override { return true; }


More information about the lyx-cvs mailing list