aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/addressbar/addressbar.cpp7
-rw-r--r--lib/addressbar/urllineedit.cpp15
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp
index 2215c0e..3768aeb 100644
--- a/lib/addressbar/addressbar.cpp
+++ b/lib/addressbar/addressbar.cpp
@@ -67,10 +67,11 @@ void AddressBar::setView(QWebEngineView *view)
urlBar->setUrl(view->url());
urlChangedConnection = connect(view, &QWebEngineView::urlChanged, urlBar, &UrlLineEdit::setUrl);
loadUrlConnection = connect(urlBar, &UrlLineEdit::returnPressed, [=]() {
- if(urlBar->text().startsWith('#')) {
- emit search(urlBar->text().mid(1));
+ const QUrl url = QUrl::fromUserInput(urlBar->text());
+ if(url.isValid()) {
+ view->load(url);
} else {
- view->load(QUrl::fromUserInput(urlBar->text()));
+ emit search(urlBar->text());
}
view->setFocus();
});
diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp
index ac311b3..79d7bf8 100644
--- a/lib/addressbar/urllineedit.cpp
+++ b/lib/addressbar/urllineedit.cpp
@@ -12,6 +12,8 @@
#include <QApplication>
#include <QClipboard>
+#include "addressbar.h"
+
UrlLineEdit::UrlLineEdit(QWidget *parent)
: QLineEdit(parent)
, m_listView(new Completer(this))
@@ -20,6 +22,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
setPlaceholderText(tr("Enter address"));
m_listView->setVisible(false);
+ auto *addressbar = qobject_cast<AddressBar *>(parent);
+ Q_CHECK_PTR(addressbar);
auto *copyAction = new QAction(tr("Copy URL"), this);
connect(copyAction, &QAction::triggered, this, [this]() {
@@ -42,9 +46,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
actions.append(loadAction);
auto *searchAction = new QAction(tr("Paste and search"), this);
- connect(searchAction, &QAction::triggered, this, [this]() {
- this->setText("#" + qApp->clipboard()->text());
- emit returnPressed();
+ connect(searchAction, &QAction::triggered, this, [=]() {
+ emit addressbar->search(qApp->clipboard()->text());
});
actions.append(searchAction);
@@ -106,8 +109,10 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
void UrlLineEdit::focusOutEvent(QFocusEvent *event)
{
- if(!text().startsWith('#'))
- setUrl(QUrl::fromUserInput(text()));
+ const QUrl url = QUrl::fromUserInput(text());
+ if(url.isValid())
+ setUrl(url);
+
QLineEdit::focusOutEvent(event);
}