From b2978113c54eb4d3e895f3f6baeddbc791d7c7b7 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Wed, 19 Nov 2025 07:32:37 +0800 Subject: [PATCH] feat(launcher): Integrate TextFormatter for enhanced preview UI --- Helpers/TextFormatter.js | 34 ++++++++++++++++++++ Modules/Panels/Launcher/ClipboardPreview.qml | 6 +++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Helpers/TextFormatter.js diff --git a/Helpers/TextFormatter.js b/Helpers/TextFormatter.js new file mode 100644 index 00000000..36f0b375 --- /dev/null +++ b/Helpers/TextFormatter.js @@ -0,0 +1,34 @@ +.pragma library + +/** + * Wrap text in a nicely styled HTML container for display + * @param {string} text - The text to display + * @returns {string} HTML string + */ +function wrapTextForDisplay(text) { + // Escape HTML special characters + const escapeHtml = (s) => + s.replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + + return ` +
+${escapeHtml(text)} +
+`; +} diff --git a/Modules/Panels/Launcher/ClipboardPreview.qml b/Modules/Panels/Launcher/ClipboardPreview.qml index 3c8e188a..7b9ee16e 100644 --- a/Modules/Panels/Launcher/ClipboardPreview.qml +++ b/Modules/Panels/Launcher/ClipboardPreview.qml @@ -4,6 +4,7 @@ import QtQuick.Controls import qs.Commons import qs.Widgets import qs.Services.Keyboard +import "../../../Helpers/TextFormatter.js" as TextFormatter Item { id: previewPanel @@ -35,7 +36,7 @@ Item { } else { loadingFullContent = true; ClipboardService.decode(currentItem.clipboardId, function(content) { - fullContent = content; + fullContent = TextFormatter.wrapTextForDisplay(content); loadingFullContent = false; }); } @@ -116,6 +117,9 @@ Item { text: fullContent readOnly: true wrapMode: Text.Wrap + textFormat: TextArea.RichText // Enable HTML rendering + font.pointSize: Style.fontSizeM // Adjust font size for readability + color: Color.mOnSurface // Consistent text color } } }