[LyX/master] Attempt at "search as you type"
Juergen Spitzmueller
spitz at lyx.org
Mon Feb 15 09:51:00 UTC 2021
commit 22542700a7213205fddb9ea006fe3b7697ed5b8f
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Mon Feb 15 10:53:23 2021 +0100
Attempt at "search as you type"
---
src/frontends/qt/GuiSearch.cpp | 24 +++++++++++++++++-------
src/frontends/qt/GuiSearch.h | 3 ++-
src/frontends/qt/ui/SearchUi.ui | 12 +++++++++++-
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index 12ec875..5f12d0f 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -173,22 +173,26 @@ void GuiSearchWidget::findBufferChanged()
void GuiSearchWidget::findChanged()
{
- findPB->setEnabled(!findCO->currentText().isEmpty());
- findPrevPB->setEnabled(!findCO->currentText().isEmpty());
- bool const replace = !findCO->currentText().isEmpty()
- && bv_ && !bv_->buffer().isReadonly();
+ bool const emptytext = findCO->currentText().isEmpty();
+ findPB->setEnabled(!emptytext);
+ findPrevPB->setEnabled(!emptytext);
+ bool const replace = !emptytext && bv_ && !bv_->buffer().isReadonly();
replacePB->setEnabled(replace);
replacePrevPB->setEnabled(replace);
replaceallPB->setEnabled(replace);
+ if (instantSearchCB->isChecked() && !emptytext)
+ findClicked();
}
void GuiSearchWidget::findClicked(bool const backwards)
{
docstring const needle = qstring_to_ucs4(findCO->currentText());
- find(needle, caseCB->isChecked(), wordsCB->isChecked(), !backwards);
+ find(needle, caseCB->isChecked(), wordsCB->isChecked(), !backwards,
+ instantSearchCB->isChecked());
uniqueInsert(findCO, findCO->currentText());
- findCO->lineEdit()->selectAll();
+ if (!instantSearchCB->isChecked())
+ findCO->lineEdit()->selectAll();
}
@@ -226,10 +230,14 @@ void GuiSearchWidget::replaceallClicked()
void GuiSearchWidget::find(docstring const & search, bool casesensitive,
- bool matchword, bool forward)
+ bool matchword, bool forward, bool instant)
{
docstring const sdata =
find2string(search, casesensitive, matchword, forward);
+ if (instant)
+ // re-query current match
+ dispatch(FuncRequest(LFUN_WORD_BACKWARD));
+
dispatch(FuncRequest(LFUN_WORD_FIND, sdata));
}
@@ -248,6 +256,7 @@ void GuiSearchWidget::saveSession(QSettings & settings, QString const & session_
{
settings.setValue(session_key + "/casesensitive", caseCB->isChecked());
settings.setValue(session_key + "/words", wordsCB->isChecked());
+ settings.setValue(session_key + "/instant", instantSearchCB->isChecked());
settings.setValue(session_key + "/minimized", minimized_);
}
@@ -257,6 +266,7 @@ void GuiSearchWidget::restoreSession(QString const & session_key)
QSettings settings;
caseCB->setChecked(settings.value(session_key + "/casesensitive", false).toBool());
wordsCB->setChecked(settings.value(session_key + "/words", false).toBool());
+ instantSearchCB->setChecked(settings.value(session_key + "/instant", false).toBool());
minimized_ = settings.value(session_key + "/minimized", false).toBool();
// initialize hidings
minimizeClicked(false);
diff --git a/src/frontends/qt/GuiSearch.h b/src/frontends/qt/GuiSearch.h
index 5898229..53d25d6 100644
--- a/src/frontends/qt/GuiSearch.h
+++ b/src/frontends/qt/GuiSearch.h
@@ -60,7 +60,8 @@ private:
void showEvent(QShowEvent * e) override;
/// Searches occurrence of string
void find(docstring const & search,
- bool casesensitive, bool matchword, bool forward);
+ bool casesensitive, bool matchword,
+ bool forward, bool instant);
/// Replaces occurrence of string
void replace(docstring const & search, docstring const & replace,
bool casesensitive, bool matchword,
diff --git a/src/frontends/qt/ui/SearchUi.ui b/src/frontends/qt/ui/SearchUi.ui
index 5d6bc05..29d3f5b 100644
--- a/src/frontends/qt/ui/SearchUi.ui
+++ b/src/frontends/qt/ui/SearchUi.ui
@@ -208,7 +208,17 @@
<item>
<widget class="QCheckBox" name="wordsCB">
<property name="text">
- <string>Match &whole words only</string>
+ <string>&Whole words</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="instantSearchCB">
+ <property name="toolTip">
+ <string>If this is checked, LyX will search forward immediately</string>
+ </property>
+ <property name="text">
+ <string>Search as you t&ype</string>
</property>
</widget>
</item>
More information about the lyx-cvs
mailing list