Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/view/web_window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -19,12 +19,13 @@
#include "controller/config_manager.h"

#include <DPlatformWindowHandle>
#include <DTitlebar>

Check warning on line 22 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DTitlebar> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QApplication>

Check warning on line 24 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLocale>

Check warning on line 25 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLocale> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QShortcut>

Check warning on line 26 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QShortcut> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QShowEvent>

Check warning on line 27 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QShowEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QWebChannel>

Check warning on line 28 in src/view/web_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QWebChannel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QWindow>
#include <QX11Info>
#include <QRegion>
Expand All @@ -42,6 +43,27 @@

const int kSearchDelay = 200;

/**
* @brief isEnglishLocale 判断当前系统语言是否为英文
*/
bool isEnglishLocale()
{
return QLocale::system().name().startsWith("en");
}

/**
* @brief filterSearchText 过滤搜索文本中的换行符;非英文环境下额外移除空白字符
*/
QString filterSearchText(const QString &text)
{
QString result = text;
result.remove('\n').remove('\r').remove("\r\n");
if (!isEnglishLocale()) {
result.remove(QRegExp("\\s"));
}
return result;
}

} // namespace

WebWindow::WebWindow(QWidget *parent)
Expand Down Expand Up @@ -874,8 +896,7 @@
void WebWindow::onSearchContentByKeyword(const QString &keyword)
{
qDebug() << "calling keyword is:" << keyword << endl;
QString key(keyword);
const QString searchKey = key.remove('\n').remove('\r').remove("\r\n").remove(QRegExp("\\s"));
const QString searchKey = filterSearchText(keyword);
//在数据库中查询->SearchDb::searchContent->SearchDb::handleSearchContent
search_manager_->searchContent(searchKey);

Expand Down Expand Up @@ -943,9 +964,7 @@
*/
void WebWindow::onSearchTextChangedDelay()
{
QString textTemp = search_edit_->text();
const QString text = textTemp.remove('\n').remove('\r').remove("\r\n").remove(QRegExp("\\s"));
// 过滤特殊字符
const QString text = filterSearchText(search_edit_->text());
if (text.size() < 1 || text.toLower().contains(QRegExp("[+-_$!@#%^&\\(\\)]"))) {
return;
}
Expand All @@ -964,8 +983,7 @@
void WebWindow::onTitleBarEntered()
{
qDebug() << Q_FUNC_INFO;
QString textTemp = search_edit_->text();
const QString text = textTemp.remove('\n').remove('\r').remove("\r\n").remove(QRegExp("\\s"));
const QString text = filterSearchText(search_edit_->text());
if (text.size() >= 1) {
completion_window_->onEnterPressed();
}
Expand Down
Loading