From d708fea839d85aca5678f5fd9cba1edff54153e1 Mon Sep 17 00:00:00 2001 From: Julian Wolff Date: Sat, 10 Mar 2018 15:04:39 +0100 Subject: [PATCH] Use selected text in searchToolBar Summary: With this patch, the currently selected text in a webpage is automatically inserted into the searchToolBar when it is opened. This matches the behaviour of the search tool bar in Kate. Test Plan: Open a webpage. Select a single line of text. Press Ctrl+F. The selected text is inserted into the searchToolBar. Reviewers: #falkon, drosca Reviewed By: #falkon, drosca Subscribers: drosca Differential Revision: https://phabricator.kde.org/D11210 --- src/lib/app/browserwindow.cpp | 7 ++++++- src/lib/webtab/searchtoolbar.cpp | 7 ++++++- src/lib/webtab/searchtoolbar.h | 1 + src/lib/webtab/webtab.cpp | 5 ++++- src/lib/webtab/webtab.h | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index bcc90ea95..5d36f4ba4 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -1148,7 +1148,12 @@ void BrowserWindow::webSearch() void BrowserWindow::searchOnPage() { if (weView() && weView()->webTab()) { - weView()->webTab()->showSearchToolBar(); + const QString searchText = weView()->page()->selectedText(); + if (!searchText.contains('\n')) { + weView()->webTab()->showSearchToolBar(searchText); + } else { + weView()->webTab()->showSearchToolBar(); + } } } diff --git a/src/lib/webtab/searchtoolbar.cpp b/src/lib/webtab/searchtoolbar.cpp index 3e9583d58..e7e940ec9 100644 --- a/src/lib/webtab/searchtoolbar.cpp +++ b/src/lib/webtab/searchtoolbar.cpp @@ -41,7 +41,7 @@ SearchToolBar::SearchToolBar(WebView* view, QWidget* parent) ui->previous->setShortcut(QKeySequence("Ctrl+Shift+G")); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); - connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(findNext())); + connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(findNext())); connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(findNext())); connect(ui->next, SIGNAL(clicked()), this, SLOT(findNext())); connect(ui->previous, SIGNAL(clicked()), this, SLOT(findPrevious())); @@ -113,6 +113,11 @@ void SearchToolBar::caseSensitivityChanged() searchText(ui->lineEdit->text()); } +void SearchToolBar::setText(const QString &text) +{ + ui->lineEdit->setText(text); +} + void SearchToolBar::searchText(const QString &text) { QPointer guard = this; diff --git a/src/lib/webtab/searchtoolbar.h b/src/lib/webtab/searchtoolbar.h index 06a60ea42..f4017783b 100644 --- a/src/lib/webtab/searchtoolbar.h +++ b/src/lib/webtab/searchtoolbar.h @@ -45,6 +45,7 @@ public: bool eventFilter(QObject* obj, QEvent* event); public Q_SLOTS: + void setText(const QString &text); void searchText(const QString &text); void updateFindFlags(); void caseSensitivityChanged(); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index 2164e740e..3fdd03be4 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -237,7 +237,7 @@ void WebTab::toggleWebInspector() delete m_splitter->widget(1); } -void WebTab::showSearchToolBar() +void WebTab::showSearchToolBar(const QString &searchText) { const int index = 1; @@ -252,6 +252,9 @@ void WebTab::showSearchToolBar() } Q_ASSERT(toolBar); + if (!searchText.isEmpty()) { + toolBar->setText(searchText); + } toolBar->focusSearchLine(); } diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index 5c83b9d00..e01bb0dfb 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -121,7 +121,7 @@ public: void showWebInspector(bool inspectElement = false); void toggleWebInspector(); - void showSearchToolBar(); + void showSearchToolBar(const QString &searchText = QString()); bool isRestored() const; void restoreTab(const SavedTab &tab);