aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2021-09-08 14:33:15 +0200
committerEike Ziller <eike.ziller@qt.io>2021-09-09 07:06:23 +0000
commit1aa92b5dabee638af54cec3eb572f349182e1613 (patch)
tree3cacfe92eb7dbe00c3fed6d5642f4ca76dd045f9 /src/plugins/texteditor
parent35095c542fde45f2617f81830cff41855f2a39db (diff)
Find: Do not try to show weird control characters in results
Replace all non-printable characters by question marks for display purposes. Fixes: QTCREATORBUG-9108 Change-Id: I81d31880dd5b1b2f9dea66acfdbe78ce89e685ca Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/basefilefind.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp
index 2f594021590..abe8777b347 100644
--- a/src/plugins/texteditor/basefilefind.cpp
+++ b/src/plugins/texteditor/basefilefind.cpp
@@ -231,6 +231,17 @@ void BaseFileFind::setCurrentSearchEngine(int index)
emit currentSearchEngineChanged();
}
+static QString displayText(const QString &line)
+{
+ QString result = line;
+ auto end = result.end();
+ for (auto it = result.begin(); it != end; ++it) {
+ if (!it->isPrint())
+ *it = QChar('?');
+ }
+ return result;
+}
+
static void displayResult(QFutureWatcher<FileSearchResultList> *watcher,
SearchResult *search, int index)
{
@@ -240,7 +251,7 @@ static void displayResult(QFutureWatcher<FileSearchResultList> *watcher,
SearchResultItem item;
item.setFilePath(Utils::FilePath::fromString(result.fileName));
item.setMainRange(result.lineNumber, result.matchStart, result.matchLength);
- item.setLineText(result.matchingLine);
+ item.setLineText(displayText(result.matchingLine));
item.setUseTextEditorFont(true);
item.setUserData(result.regexpCapturedTexts);
items << item;