Commit fd9b2f20 authored by Kåre Särs's avatar Kåre Särs
Browse files

Fix multi-line replace match ranges/marks

parent 8bc6db80
...@@ -242,9 +242,6 @@ bool MatchModel::replaceMatch(KTextEditor::Document *doc, const QModelIndex &mat ...@@ -242,9 +242,6 @@ bool MatchModel::replaceMatch(KTextEditor::Document *doc, const QModelIndex &mat
int newEndColumn = lastNL == -1 ? matchItem->range.start().column() + replaceText.length() : replaceText.length() - lastNL - 1; int newEndColumn = lastNL == -1 ? matchItem->range.start().column() + replaceText.length() : replaceText.length() - lastNL - 1;
matchItem->range.setEnd(KTextEditor::Cursor{newEndLine, newEndColumn}); matchItem->range.setEnd(KTextEditor::Cursor{newEndLine, newEndColumn});
// Convert replace text back to "html"
replaceText.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
replaceText.replace(QLatin1Char('\t'), QStringLiteral("\\t"));
matchItem->replaceText = replaceText; matchItem->replaceText = replaceText;
return true; return true;
} }
...@@ -485,10 +482,10 @@ QString MatchModel::matchToHtmlString(const Match &match) const ...@@ -485,10 +482,10 @@ QString MatchModel::matchToHtmlString(const Match &match) const
} }
pre = pre.toHtmlEscaped(); pre = pre.toHtmlEscaped();
QString matchStr = match.matchStr; QString matchStr = match.matchStr.toHtmlEscaped();;
matchStr.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
matchStr = matchStr.toHtmlEscaped();
QString replaceStr = match.replaceText.toHtmlEscaped(); QString replaceStr = match.replaceText.toHtmlEscaped();
if (!replaceStr.isEmpty()) { if (!replaceStr.isEmpty()) {
matchStr = QLatin1String("<i><s>") + matchStr + QLatin1String("</s></i> "); matchStr = QLatin1String("<i><s>") + matchStr + QLatin1String("</s></i> ");
} }
...@@ -500,6 +497,9 @@ QString MatchModel::matchToHtmlString(const Match &match) const ...@@ -500,6 +497,9 @@ QString MatchModel::matchToHtmlString(const Match &match) const
.arg(m_replaceHighlightColor.name(), m_foregroundColor.name(), replaceStr); .arg(m_replaceHighlightColor.name(), m_foregroundColor.name(), replaceStr);
} }
matchStr.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
matchStr.replace(QLatin1Char('\t'), QStringLiteral("\\t"));
QString post = match.postMatchStr; QString post = match.postMatchStr;
int nlIndex = post.indexOf(QLatin1Char('\n')); int nlIndex = post.indexOf(QLatin1Char('\n'));
if (nlIndex != -1) { if (nlIndex != -1) {
...@@ -602,6 +602,11 @@ QString MatchModel::matchToPlainText(const Match &match) const ...@@ -602,6 +602,11 @@ QString MatchModel::matchToPlainText(const Match &match) const
} }
QString post = match.postMatchStr; QString post = match.postMatchStr;
matchStr.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
matchStr.replace(QLatin1Char('\t'), QStringLiteral("\\t"));
replaceStr.replace(QLatin1Char('\n'), QStringLiteral("\\n"));
replaceStr.replace(QLatin1Char('\t'), QStringLiteral("\\t"));
// (line:col)[space][space] ...Line text pre [highlighted match] Line text post.... // (line:col)[space][space] ...Line text pre [highlighted match] Line text post....
QString displayText = QStringLiteral("(%1:%2) ") QString displayText = QStringLiteral("(%1:%2) ")
.arg(match.range.start().line() + 1, 3) .arg(match.range.start().line() + 1, 3)
......
...@@ -798,7 +798,7 @@ void KatePluginSearchView::addMatchMark(KTextEditor::Document *doc, const QModel ...@@ -798,7 +798,7 @@ void KatePluginSearchView::addMatchMark(KTextEditor::Document *doc, const QModel
} }
} else { } else {
if (doc->text(range) != itemIndex.data(MatchModel::ReplaceTextRole).toString()) { if (doc->text(range) != itemIndex.data(MatchModel::ReplaceTextRole).toString()) {
// qDebug() << doc->text(range) << "Does not match" << item->data(0, ReplaceMatches::ReplacedTextRole).toString(); ///qDebug() << doc->text(range) << "Does not match" << itemIndex.data(MatchModel::ReplaceTextRole).toString();
return; return;
} }
} }
......
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