feat(launcher): Integrate TextFormatter for enhanced preview UI

This commit is contained in:
loner
2025-11-19 07:32:37 +08:00
parent 87f62b288b
commit b2978113c5
2 changed files with 39 additions and 1 deletions

34
Helpers/TextFormatter.js Normal file
View File

@@ -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, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
return `
<div style="
font-family: 'Fira Code', 'Courier New', monospace;
white-space: pre-wrap;
background: linear-gradient(135deg, #2c3e50, #34495e);
color: #ecf0f1;
padding: 16px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
overflow-x: auto;
line-height: 1.5;
font-size: 14px;
border: 1px solid #3d566e;
">
${escapeHtml(text)}
</div>
`;
}

View File

@@ -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
}
}
}