Commit b67396c7 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Show the line text in search results

This is a proposal.

Currently search & replace plugin shows "Line: xx, Column: xx"
which IMO is not very useful. With this change the actual line
is displayed with the matching text highlighted in the same color
as that of the editor search-highlight color.

This makes the search plugin very useful for cases where you want
to see some very similar lines or see uses of something. An example
use case which I often come across is that suppose you have a big log
file and you are looking for only WARNs. You just type WARN and in
search results you see all the lines that contain WARN. Now you can
quickly analyze them.
parent c935ea29
......@@ -949,35 +949,21 @@ void KatePluginSearchView::addMatchMark(KTextEditor::Document *doc, QTreeWidgetI
connect(doc, SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clearMarks()), Qt::UniqueConnection);
static const int contextLen = 70;
void KatePluginSearchView::matchFound(const QString &url, const QString &fName, const QString &lineContent, int matchLen, int startLine, int startColumn, int endLine, int endColumn)
if (!m_curResults || (sender() == &m_searchDiskFiles && m_blockDiskMatchFound)) {
int preLen = contextLen;
int preStart = startColumn - preLen;
if (preStart < 0) {
preLen += preStart;
preStart = 0;
QString pre;
if (preLen == contextLen) {
pre = QStringLiteral("...");
pre += lineContent.mid(preStart, preLen).toHtmlEscaped();
QString match = lineContent.mid(startColumn, matchLen).toHtmlEscaped();
QString pre = lineContent.mid(0, startColumn).toHtmlEscaped();
QString match = lineContent.mid(startColumn, matchLen);
match.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
QString post = lineContent.mid(startColumn + matchLen, contextLen);
if (post.size() >= contextLen) {
post += QStringLiteral("...");
post = post.toHtmlEscaped();
QStringList row;
row << i18n("Line: <b>%1</b> Column: <b>%2</b>: %3", startLine + 1, startColumn + 1, pre + QStringLiteral("<b>") + match + QStringLiteral("</b>") + post);
QString post = lineContent.mid(startColumn + matchLen).toHtmlEscaped();
QString style = QStringLiteral("<span style=\"background-color:") + m_searchBackgroundColor + QStringLiteral(";\">");
TreeWidgetItem *item = new TreeWidgetItem(static_cast<TreeWidgetItem*>(nullptr), row);
QStringList txt{pre};
TreeWidgetItem *item = new TreeWidgetItem(static_cast<TreeWidgetItem*>(nullptr), txt);
item->setData(0, ReplaceMatches::FileUrlRole, url);
item->setData(0, Qt::ToolTipRole, url);
......@@ -1111,6 +1097,11 @@ void KatePluginSearchView::startSearch()
// search color to use in search results
KTextEditor::ConfigInterface *ciface = qobject_cast<KTextEditor::ConfigInterface *>(m_mainWindow->activeView());
if (ciface)
m_searchBackgroundColor = ciface->configValue(QStringLiteral("search-highlight-color")).value<QColor>().name();
m_curResults->regExp = reg;
m_curResults->useRegExp = m_ui.useRegExp->isChecked();
m_curResults->matchCase = m_ui.matchCase->isChecked();
......@@ -206,6 +206,7 @@ private:
QTimer m_changeTimer;
QTimer m_updateSumaryTimer;
QPointer<KTextEditor::Message> m_infoMessage;
QString m_searchBackgroundColor;
* current project plugin view, if any
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment