feat: add search engine selection and context menu search functionality (#6743)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
leafyzito
2026-01-24 15:31:39 -01:00
committed by GitHub
parent f2c4c63d59
commit 2dbed2f03d
4 changed files with 107 additions and 0 deletions
+16
View File
@@ -310,6 +310,22 @@ public:
BoolSetting autoCloseThreadPopup = {"/behaviour/autoCloseThreadPopup",
false};
/// Specifies whether the search functionality should be enabled
BoolSetting searchEnabled = {
"/behaviour/search/enabled",
false,
};
/// The URL of the search engine
QStringSetting searchEngineUrl = {
"/behaviour/search/engineUrl",
"",
};
/// The name of the search engine
QStringSetting searchEngineName = {
"/behaviour/search/engineName",
"",
};
EnumSetting<UsernameRightClickBehavior> usernameRightClickBehavior = {
"/behaviour/usernameRightClickBehavior",
UsernameRightClickBehavior::Mention,
+20
View File
@@ -66,6 +66,7 @@
#include <QPainter>
#include <QScreen>
#include <QStringBuilder>
#include <QUrl>
#include <QVariantAnimation>
#include <algorithm>
@@ -2710,6 +2711,25 @@ void ChannelView::addMessageContextMenuItems(QMenu *menu,
}
}
// Add search action when text is selected and search feature is enabled
if (!this->selection_.isEmpty() && getSettings()->searchEnabled.getValue())
{
QString searchURL = getSettings()->searchEngineUrl.getValue();
QString searchName = getSettings()->searchEngineName.getValue();
if (!searchURL.isEmpty())
{
QString actionText =
searchName.isEmpty() ? "&Search" : "&Search with " + searchName;
menu->addAction(actionText, [this, searchURL] {
QString query = this->getSelectedText().trimmed();
QString encodedQuery = QUrl::toPercentEncoding(query);
QDesktopServices::openUrl(QUrl(searchURL + encodedQuery));
});
}
}
auto *twitchChannel =
dynamic_cast<TwitchChannel *>(this->underlyingChannel_.get());
if (!layout->getMessage()->id.isEmpty() && twitchChannel &&
+70
View File
@@ -31,6 +31,8 @@
#include <QFormLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPalette>
#include <QSignalBlocker>
namespace {
@@ -1214,6 +1216,74 @@ void GeneralPage::initLayout(GeneralPageView &layout)
"the top and a positive to the bottom.")
->addTo(layout);
{
layout.addSubtitle("Search");
layout.addDescription(
"Search engine which appears when you select text and right-click "
"a message. Select a search engine preset from the dropdown below, "
"or fill in your custom search engine URL and name.");
SettingWidget::checkbox("Enable search in right-click context menu",
s.searchEnabled)
->setTooltip(
"Allow searching selected text using a search engine from "
"the right-click context menu.")
->addTo(layout);
// Preset dropdown
QStringList presetList = {"DuckDuckGo", "Bing", "Google"};
auto *presetCombo =
layout.addDropdown("Search engine preset", presetList,
"Select a search engine preset");
presetCombo->setPlaceholderText("Select...");
presetCombo->setCurrentIndex(-1);
// Make placeholder text more visible
QPalette palette = presetCombo->palette();
palette.setColor(QPalette::PlaceholderText,
QColor(255, 255, 255)); // white
presetCombo->setPalette(palette);
s.searchEnabled.connect([presetCombo](bool value) {
presetCombo->setEnabled(value);
});
// Connect preset dropdown to update URL and name settings
QObject::connect(
presetCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
[&s, presetCombo](int index) {
if (index < 0)
return;
QString preset = presetCombo->itemText(index);
if (preset == "DuckDuckGo")
{
s.searchEngineUrl = "https://duckduckgo.com/?q=";
s.searchEngineName = "DuckDuckGo";
}
else if (preset == "Bing")
{
s.searchEngineUrl = "https://www.bing.com/search?q=";
s.searchEngineName = "Bing";
}
else if (preset == "Google")
{
s.searchEngineUrl = "https://www.google.com/search?q=";
s.searchEngineName = "Google";
}
// Reset to -1 after selection
{
QSignalBlocker blocker(presetCombo);
presetCombo->setCurrentIndex(-1);
}
});
// URL and Name text inputs
SettingWidget::lineEdit("Search engine URL", s.searchEngineUrl)
->conditionallyEnabledBy(s.searchEnabled)
->addTo(layout);
SettingWidget::lineEdit("Search engine name", s.searchEngineName)
->conditionallyEnabledBy(s.searchEnabled)
->addTo(layout);
}
layout.addSubtitle("Miscellaneous");
if (supportsIncognitoLinks())