diff options
| author | Méven Car <[email protected]> | 2023-09-10 15:24:39 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2023-09-10 15:24:39 +0200 |
| commit | 4cbeb81b2b8e2d37c93cda4d88787e08e0658291 (patch) | |
| tree | 013a28405e8011fd5a5a5c514aaf3daa395a42b1 /src/search | |
| parent | 0ed26df6a9074b71ae247017e1080b2285b73438 (diff) | |
| parent | 5c33e0211ff09f37adb5b48c59cf15b67c0059dc (diff) | |
Merge remote-tracking branch 'origin/master' into kf6
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/dolphinquery.cpp | 2 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 25 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.h | 5 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp index f9e5da84f..ed2a6a766 100644 --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -49,7 +49,7 @@ QStringList splitOutsideQuotes(const QString &text) // - Groups with two leading quotes must close both on them (filename:""abc xyz" tuv") // - Groups enclosed in quotes // - Words separated by spaces - const QRegularExpression subTermsRegExp("(\\S*?\"\"[^\"]+\"[^\"]+\"+|\\S*?\"[^\"]+\"+|(?<=\\s|^)\\S+(?=\\s|$))"); + static const QRegularExpression subTermsRegExp("(\\S*?\"\"[^\"]+\"[^\"]+\"+|\\S*?\"[^\"]+\"+|(?<=\\s|^)\\S+(?=\\s|$))"); auto subTermsMatchIterator = subTermsRegExp.globalMatch(text); QStringList textParts; diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 9df417c4f..a09f25293 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -60,7 +60,9 @@ DolphinSearchBox::~DolphinSearchBox() void DolphinSearchBox::setText(const QString &text) { - m_searchInput->setText(text); + if (m_searchInput->text() != text) { + m_searchInput->setText(text); + } } QString DolphinSearchBox::text() const @@ -201,7 +203,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event) QWidget::keyReleaseEvent(event); if (event->key() == Qt::Key_Escape) { if (m_searchInput->text().isEmpty()) { - Q_EMIT closeRequest(); + emitCloseRequest(); } else { m_searchInput->clear(); } @@ -261,7 +263,11 @@ void DolphinSearchBox::slotConfigurationChanged() void DolphinSearchBox::slotSearchTextChanged(const QString &text) { if (text.isEmpty()) { - m_startSearchTimer->stop(); + // Restore URL when search box is cleared by closing and reopening the box. + emitCloseRequest(); + QTimer::singleShot(0, this, [this] { + Q_EMIT openRequest(); + }); } else { m_startSearchTimer->start(); } @@ -270,6 +276,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text) void DolphinSearchBox::slotReturnPressed() { + if (m_searchInput->text().isEmpty()) { + return; + } + emitSearchRequest(); Q_EMIT focusViewRequest(); } @@ -443,10 +453,10 @@ void DolphinSearchBox::init() loadSettings(); // The searching should be started automatically after the user did not change - // the text within one second + // the text for a while m_startSearchTimer = new QTimer(this); m_startSearchTimer->setSingleShot(true); - m_startSearchTimer->setInterval(1000); + m_startSearchTimer->setInterval(500); connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest); } @@ -496,10 +506,7 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery &query) setSearchPath(QUrl::fromLocalFile(QDir::homePath())); } - // If the input box has focus, do not update to avoid messing with user typing - if (!m_searchInput->hasFocus()) { - setText(query.text()); - } + setText(query.text()); if (query.hasContentSearch()) { m_contentButton->setChecked(true); diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 4ccb7ac10..b73c2899f 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -112,6 +112,11 @@ Q_SIGNALS: void closeRequest(); /** + * Is emitted when the search box should be opened. + */ + void openRequest(); + + /** * Is emitted, if the searchbox has been activated by * an user interaction * @see DolphinSearchBox::setActive() |
