diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-04-19 17:56:03 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-04-19 17:56:03 +0530 |
| commit | 0e95e99e72237058465959d55b77750a9d7c1bef (patch) | |
| tree | 5b99cd64f7c49b949a6381c4654ec253822934b5 /src/widgets/WebViewStack.cpp | |
| parent | 7a458b424c2c1a6ed251211b25261acffef59b7f (diff) | |
| download | null-browser-0e95e99e72237058465959d55b77750a9d7c1bef.tar.gz null-browser-0e95e99e72237058465959d55b77750a9d7c1bef.zip | |
Add web.search and search text implemnetation
Diffstat (limited to 'src/widgets/WebViewStack.cpp')
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 258fbc6..16fd3e9 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -1,4 +1,5 @@ #include <QStackedLayout> +#include <QWebEngineFindTextResult> #include <QWebEngineHistory> #include <QWebEngineNewWindowRequest> #include <QWebEngineProfile> @@ -198,6 +199,25 @@ void WebViewStack::focus_webview(WebViewId webview_id) { layout->setCurrentIndex((int)webview_index); } +void WebViewStack::set_search_text(const QString &text, WebViewId webview_id, bool forward) { + auto *webview = get_webview(webview_id); + if (webview == nullptr) { + qDebug() << "Webview does not exist"; + return; + } + + QString search_text = text.trimmed(); + + auto flags = + search_text.isLower() ? QWebEnginePage::FindFlags() : QWebEnginePage::FindCaseSensitively; + if (!forward) + flags |= QWebEnginePage::FindBackward; + + webview->page()->findText(search_text, flags, [](const QWebEngineFindTextResult &result) { + qDebug() << result.numberOfMatches() << result.activeMatch(); + }); +} + WebView *WebViewStack::get_webview(WebViewId webview_id) { auto webview_index = get_webview_index(webview_id); if (webview_index < 0) |
