mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
feat(launcher): Integrate TextFormatter for enhanced preview UI
This commit is contained in:
34
Helpers/TextFormatter.js
Normal file
34
Helpers/TextFormatter.js
Normal 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, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
|
||||
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>
|
||||
`;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user