From 155153a7630788cc3bdad6a5d48a0d18456f1c26 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Wed, 30 Apr 2025 21:23:43 +0200 Subject: [PATCH] fix: Optimize searching unreadable symbols for markdown --- ChatView/ChatUtils.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ChatView/ChatUtils.cpp b/ChatView/ChatUtils.cpp index d6d0409..0624f5c 100644 --- a/ChatView/ChatUtils.cpp +++ b/ChatView/ChatUtils.cpp @@ -31,7 +31,22 @@ void ChatUtils::copyToClipboard(const QString &text) QString ChatUtils::getSafeMarkdownText(const QString &text) const { - // TODO replace to QTextMarkdownImporter after QtC on Qt6.9.0 + if (text.isEmpty()) { + return text; + } + + bool needsSanitization = false; + for (const QChar &ch : text) { + if (ch.isNull() || (!ch.isPrint() && ch != '\n' && ch != '\t' && ch != '\r' && ch != ' ')) { + needsSanitization = true; + break; + } + } + + if (!needsSanitization) { + return text; + } + QString safeText; safeText.reserve(text.size());