diff --git a/src/plugins/ProjectManager/ProjectManagerPlg.cpp b/src/plugins/ProjectManager/ProjectManagerPlg.cpp index e412c2dd..8b0ba4d4 100644 --- a/src/plugins/ProjectManager/ProjectManagerPlg.cpp +++ b/src/plugins/ProjectManager/ProjectManagerPlg.cpp @@ -616,6 +616,11 @@ void ProjectManagerPlugin::on_client_merged(qmdiHost *host) { auto projectSearch = new QAction(tr("Search in project")); projectSearch->setShortcut(QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_F)); connect(projectSearch, &QAction::triggered, this, [searchPanel, this]() { + auto currentEditor = dynamic_cast(getManager()->currentClient()); + if (currentEditor) { + auto text = currentEditor->getSelectedText(); + searchPanelUI->setSearchPattern(text); + } searchPanel->raise(); searchPanel->show(); searchPanel->setFocus(); diff --git a/src/plugins/ProjectManager/ProjectSearch.cpp b/src/plugins/ProjectManager/ProjectSearch.cpp index 1da22ca0..bbe570d9 100644 --- a/src/plugins/ProjectManager/ProjectSearch.cpp +++ b/src/plugins/ProjectManager/ProjectSearch.cpp @@ -224,7 +224,10 @@ void ProjectSearch::setSearchPath(const QString &s) { ui->pathEdit->setText(s); const QString ProjectSearch::getSearchPattern() { return ui->searchFor->text(); } -void ProjectSearch::setSearchPattern(const QString &s) { ui->searchFor->setText(s); } +void ProjectSearch::setSearchPattern(const QString &s) { + ui->searchFor->setText(s); + ui->searchFor->selectAll(); +} const QString ProjectSearch::getSearchInclude() { return ui->includeFiles->text(); } diff --git a/src/widgets/qmdieditor.cpp b/src/widgets/qmdieditor.cpp index 195af8bc..1cdd20d9 100644 --- a/src/widgets/qmdieditor.cpp +++ b/src/widgets/qmdieditor.cpp @@ -898,6 +898,12 @@ void qmdiEditor::goTo(int x, int y) { } } +QString qmdiEditor::getSelectedText() const +{ + auto cursor = textEditor->textCursor(); + return cursor.selectedText(); +} + void qmdiEditor::focusInEvent(QFocusEvent *event) { QWidget::focusInEvent(event); diff --git a/src/widgets/qmdieditor.h b/src/widgets/qmdieditor.h index 13ade1aa..a7c87b96 100644 --- a/src/widgets/qmdieditor.h +++ b/src/widgets/qmdieditor.h @@ -88,6 +88,8 @@ class qmdiEditor : public QWidget, public qmdiClient { isJSONDocument(); } + QString getSelectedText() const; + public slots: void on_fileChanged(const QString &filename); void displayBannerMessage(QString message, int time);