Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [search functionality] Resolve issue with empty editor content #1047

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
23 changes: 20 additions & 3 deletions src/plugins/find/gui/advancedsearchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class AdvancedSearchWidgetPrivate : public QObject
WindowService *winSrv { nullptr };
MainController *controller { nullptr };
QTimer startTimer;
bool isReplaceAll { false };
};

AdvancedSearchWidgetPrivate::AdvancedSearchWidgetPrivate(AdvancedSearchWidget *qq)
Expand Down Expand Up @@ -179,7 +180,7 @@ DToolButton *AdvancedSearchWidgetPrivate::registerOperator(const QIcon &icon, co
btn->setIconSize({ 16, 16 });
btn->setToolTip(description);
connect(btn, &DToolButton::clicked, this, handler);

winSrv->registerWidgetToDockHeader(MWNA_ADVANCEDSEARCH, btn);
return btn;
}
Expand Down Expand Up @@ -461,19 +462,35 @@ void AdvancedSearchWidgetPrivate::handleReplaceAll()
}
// 0: cancel 1:contionue
int code = showMessage(msg);
if (1 == code)
if (1 == code) {
isReplaceAll = true;
replace(resultMap);
}
}

void AdvancedSearchWidgetPrivate::handleReplaceFinished()
{
searchSpinner->setVisible(false);
searchSpinner->stop();
if (isReplaceAll) {
isReplaceAll = false;
const auto &results = resultWidget->allResult();
const auto &items = results.values();
const int resultCount = std::accumulate(items.cbegin(), items.cend(), 0,
[](int sum, const FindItemList &list) {
return sum + list.size();
});
QString msg = AdvancedSearchWidget::tr("Replaced %1 occurrences across %2 files with \"%3\"");
resultWidget->clear();
resultWidget->showMessage(msg.arg(QString::number(results.count()),
QString::number(resultCount),
replaceEdit->text()));
}
}

AdvancedSearchWidget::AdvancedSearchWidget(QWidget *parent)
: QWidget(parent),
d(new AdvancedSearchWidgetPrivate(this))
d(new AdvancedSearchWidgetPrivate(this))
{
d->initUI();
d->initConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void SearchReplaceWorkerPrivate::startNextJob()
process->setProgram(job.program);
process->setArguments(job.arguments);
process->start();
if (!job.channelData.isEmpty()) {
process->write(job.channelData.toUtf8());
if (job.channelData.has_value()) {
process->write(job.channelData->toUtf8());
process->closeWriteChannel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SearchReplaceWorkerPrivate : public QObject
{
QString program;
QStringList arguments;
QString channelData;
std::optional<QString> channelData;
QString keyword;
SearchFlags flags;
};
Expand Down
Loading