Commit 2b97a197 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

use KTextEditor::Range

parent c666e26a
......@@ -124,7 +124,7 @@ void SearchDiskFiles::searchSingleLineRegExp(const QString &fileName)
if (line.length() > 1024)
line = line.left(1024);
matches.push_back(KateSearchMatch{line, match.capturedLength(), i, column, i, column + match.capturedLength()});
matches.push_back(KateSearchMatch{line, match.capturedLength(), KTextEditor::Range{i, column, i, column + match.capturedLength()}});
match = m_regExp.match(line, column + match.capturedLength());
column = match.capturedStart();
......@@ -198,7 +198,7 @@ void SearchDiskFiles::searchMultiLineRegExp(const QString &fileName)
int endLine = line + match.captured().count(QLatin1Char('\n'));
int lastNL = match.captured().lastIndexOf(QLatin1Char('\n'));
int endColumn = lastNL == -1 ? startColumn + match.captured().length() : match.captured().length() - lastNL - 1;
matches.push_back(KateSearchMatch{fullDoc.mid(lineStart[line], column - lineStart[line]) + match.captured(), match.capturedLength(), line, startColumn, endLine, endColumn});
matches.push_back(KateSearchMatch{fullDoc.mid(lineStart[line], column - lineStart[line]) + match.captured(), match.capturedLength(), KTextEditor::Range{line, startColumn, endLine, endColumn}});
match = tmpRegExp.match(fullDoc, column + match.capturedLength());
column = match.capturedStart();
m_matchCount++;
......
......@@ -26,6 +26,8 @@
#include <QThread>
#include <QVector>
#include <KTextEditor/Range>
/**
* data holder for one match in one file
* used to transfer multiple matches at once via signals to avoid heavy costs for files with a lot of matches
......@@ -35,10 +37,7 @@ class KateSearchMatch
public:
QString lineContent;
int matchLen;
int startLine;
int startColumn;
int endLine;
int endColumn;
KTextEditor::Range matchRange;
};
Q_DECLARE_METATYPE(KateSearchMatch)
......
......@@ -968,7 +968,7 @@ void KatePluginSearchView::matchesFound(const QString &url, const QString &fName
QList<QTreeWidgetItem *> items;
for (const auto &searchMatch : searchMatches) {
int preLen = contextLen;
int preStart = searchMatch.startColumn - preLen;
int preStart = searchMatch.matchRange.start().column() - preLen;
if (preStart < 0) {
preLen += preStart;
preStart = 0;
......@@ -978,16 +978,16 @@ void KatePluginSearchView::matchesFound(const QString &url, const QString &fName
pre = QStringLiteral("...");
}
pre += searchMatch.lineContent.mid(preStart, preLen).toHtmlEscaped();
QString match = searchMatch.lineContent.mid(searchMatch.startColumn, searchMatch.matchLen).toHtmlEscaped();
QString match = searchMatch.lineContent.mid(searchMatch.matchRange.start().column(), searchMatch.matchLen).toHtmlEscaped();
match.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
QString post = searchMatch.lineContent.mid(searchMatch.startColumn + searchMatch.matchLen, contextLen);
QString post = searchMatch.lineContent.mid(searchMatch.matchRange.start().column() + searchMatch.matchLen, contextLen);
if (post.size() >= contextLen) {
post += QStringLiteral("...");
}
post = post.toHtmlEscaped();
// (line:col)[space][space] ...Line text pre [highlighted match] Line text post....
QString displayText = QStringLiteral("(<b>%1:%2</b>) &nbsp;").arg(searchMatch.startLine + 1).arg(searchMatch.startColumn + 1);
QString displayText = QStringLiteral("(<b>%1:%2</b>) &nbsp;").arg(searchMatch.matchRange.start().line() + 1).arg(searchMatch.matchRange.start().column() + 1);
QString matchHighlighted = QStringLiteral("<span style=\"background-color:%1; color:%2;\">%3</span>").arg(m_searchBackgroundColor.color().name()).arg(m_foregroundColor.color().name()).arg(match);
displayText = displayText + pre + matchHighlighted + post;
......@@ -996,14 +996,14 @@ void KatePluginSearchView::matchesFound(const QString &url, const QString &fName
item->setData(0, ReplaceMatches::FileUrlRole, url);
item->setData(0, Qt::ToolTipRole, url);
item->setData(0, ReplaceMatches::FileNameRole, fName);
item->setData(0, ReplaceMatches::StartLineRole, searchMatch.startLine);
item->setData(0, ReplaceMatches::StartColumnRole, searchMatch.startColumn);
item->setData(0, ReplaceMatches::StartLineRole, searchMatch.matchRange.start().line());
item->setData(0, ReplaceMatches::StartColumnRole, searchMatch.matchRange.start().column());
item->setData(0, ReplaceMatches::MatchLenRole, searchMatch.matchLen);
item->setData(0, ReplaceMatches::PreMatchRole, pre);
item->setData(0, ReplaceMatches::MatchRole, match);
item->setData(0, ReplaceMatches::PostMatchRole, post);
item->setData(0, ReplaceMatches::EndLineRole, searchMatch.endLine);
item->setData(0, ReplaceMatches::EndColumnRole, searchMatch.endColumn);
item->setData(0, ReplaceMatches::EndLineRole, searchMatch.matchRange.end().line());
item->setData(0, ReplaceMatches::EndColumnRole, searchMatch.matchRange.end().column());
item->setCheckState(0, Qt::Checked);
items.push_back(item);
}
......
......@@ -120,7 +120,7 @@ int SearchOpenFiles::searchSingleLineRegExp(KTextEditor::Document *doc, const QR
match = regExp.match(doc->line(line));
column = match.capturedStart();
while (column != -1 && !match.captured().isEmpty()) {
matches.push_back(KateSearchMatch{doc->line(line), match.capturedLength(), line, column, line, column + match.capturedLength()});
matches.push_back(KateSearchMatch{doc->line(line), match.capturedLength(), KTextEditor::Range{line, column, line, column + match.capturedLength()}});
match = regExp.match(doc->line(line), column + match.capturedLength());
column = match.capturedStart();
}
......@@ -195,7 +195,7 @@ int SearchOpenFiles::searchMultiLineRegExp(KTextEditor::Document *doc, const QRe
int lastNL = match.captured().lastIndexOf(QLatin1Char('\n'));
int endColumn = lastNL == -1 ? startColumn + match.captured().length() : match.captured().length() - lastNL - 1;
matches.push_back(KateSearchMatch{doc->line(startLine).left(column - m_lineStart[startLine]) + match.captured(), match.capturedLength(), startLine, startColumn, endLine, endColumn});
matches.push_back(KateSearchMatch{doc->line(startLine).left(column - m_lineStart[startLine]) + match.captured(), match.capturedLength(), KTextEditor::Range{startLine, startColumn, endLine, endColumn}});
match = tmpRegExp.match(m_fullDoc, column + match.capturedLength());
column = match.capturedStart();
......
......@@ -24,7 +24,7 @@
#include <QTimer>
#include <ktexteditor/document.h>
#include <SearchDiskFiles.h>
#include "SearchDiskFiles.h"
class SearchOpenFiles : public QObject
{
......
Markdown is supported
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