1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

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
This commit is contained in:
Julian Wolff 2018-03-10 15:04:39 +01:00
parent a5223ddb0c
commit d708fea839
5 changed files with 18 additions and 4 deletions

View File

@ -1148,8 +1148,13 @@ void BrowserWindow::webSearch()
void BrowserWindow::searchOnPage()
{
if (weView() && weView()->webTab()) {
const QString searchText = weView()->page()->selectedText();
if (!searchText.contains('\n')) {
weView()->webTab()->showSearchToolBar(searchText);
} else {
weView()->webTab()->showSearchToolBar();
}
}
}
void BrowserWindow::openFile()

View File

@ -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<SearchToolBar> guard = this;

View File

@ -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();

View File

@ -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();
}

View File

@ -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);