1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-07 19:59:14 -04:00

Show full clipboard text in editor

This commit is contained in:
Nachum Barcohen
2026-03-05 01:40:15 +02:00
committed by purian23
parent 8abdff3220
commit e92da4a15f
@@ -289,6 +289,47 @@ DankModal {
editField.forceActiveFocus(); editField.forceActiveFocus();
} }
}); });
if (!newEntry || newEntry.isImage) {
return;
}
const requestedId = newEntry.id;
DMSService.sendRequest("clipboard.getEntry", {
"id": requestedId
}, function (response) {
if (response.error) {
return;
}
if (!editorView.entry || editorView.entry.id !== requestedId) {
return;
}
const rawText = response.result?.text ?? response.result?.content ?? response.result?.data ?? "";
let fullText = rawText;
try {
const sanitized = rawText.replace(/\s+/g, "");
const decoder = (typeof Qt !== "undefined" && typeof Qt.atob === "function") ? Qt.atob : (typeof atob === "function" ? atob : null);
if (decoder) {
const decoded = decoder(sanitized);
fullText = decoded;
try {
fullText = decodeURIComponent(escape(decoded));
} catch (e) {
fullText = decoded;
}
}
} catch (e) {
fullText = rawText;
}
if (!fullText || fullText.length === 0) {
return;
}
editorView.editorText = fullText;
if (editField) {
editField.text = fullText;
}
});
} }
function saveEntry(action) { function saveEntry(action) {
@@ -302,7 +343,11 @@ DankModal {
} }
if (saveAction === "history") { if (saveAction === "history") {
clipboardHistoryModal.mode = "history"; clipboardHistoryModal.mode = "history";
clipboardHistoryModal.refreshClipboard(); Qt.callLater(function () {
ClipboardService.reset();
ClipboardService.refresh();
keyboardController.reset();
});
return; return;
} }
if (saveAction === "close") { if (saveAction === "close") {
@@ -346,6 +391,7 @@ DankModal {
spacing: Theme.spacingM spacing: Theme.spacingM
Item { Item {
id: editorHeader
width: parent.width width: parent.width
height: ClipboardConstants.headerHeight height: ClipboardConstants.headerHeight
@@ -379,7 +425,7 @@ DankModal {
StyledRect { StyledRect {
id: editFieldContainer id: editFieldContainer
width: parent.width width: parent.width
height: Math.max(Theme.fontSizeMedium * 8, Theme.fontSizeMedium * 3) height: Math.max(Theme.fontSizeMedium * 8, parent.height - editorHeader.height - editorActions.height - Theme.spacingM * 2)
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency) color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
border.color: editField.activeFocus ? Theme.primary : Theme.outlineMedium border.color: editField.activeFocus ? Theme.primary : Theme.outlineMedium
@@ -397,8 +443,8 @@ DankModal {
anchors.topMargin: Theme.spacingM anchors.topMargin: Theme.spacingM
} }
TextEdit { DankFlickable {
id: editField id: editScroll
anchors.left: editIcon.right anchors.left: editIcon.right
anchors.leftMargin: Theme.spacingS anchors.leftMargin: Theme.spacingS
anchors.right: parent.right anchors.right: parent.right
@@ -407,26 +453,34 @@ DankModal {
anchors.rightMargin: Theme.spacingM anchors.rightMargin: Theme.spacingM
anchors.topMargin: Theme.spacingS anchors.topMargin: Theme.spacingS
anchors.bottomMargin: Theme.spacingS anchors.bottomMargin: Theme.spacingS
text: editorView.editorText clip: true
font.pixelSize: Theme.fontSizeMedium contentWidth: width
color: Theme.surfaceText contentHeight: editField.height
wrapMode: TextEdit.Wrap
selectByMouse: true
Keys.forwardTo: [clipboardHistoryModal.modalFocusScope]
onTextChanged: editorView.editorText = text
Keys.onPressed: function (event) {
const hasCtrl = (event.modifiers & Qt.ControlModifier) !== 0;
const hasShift = (event.modifiers & Qt.ShiftModifier) !== 0;
if (hasCtrl && event.key === Qt.Key_S) { TextEdit {
editorView.saveEntry(hasShift ? "close" : "history"); id: editField
event.accepted = true; width: editScroll.width
return; height: Math.max(editScroll.height, contentHeight)
} text: editorView.editorText
if (hasCtrl && hasShift && event.key === Qt.Key_V) { font.pixelSize: Theme.fontSizeMedium
editorView.saveEntry("paste"); color: Theme.surfaceText
event.accepted = true; wrapMode: TextEdit.Wrap
return; selectByMouse: true
onTextChanged: editorView.editorText = text
Keys.onPressed: function (event) {
const hasCtrl = (event.modifiers & Qt.ControlModifier) !== 0;
const hasShift = (event.modifiers & Qt.ShiftModifier) !== 0;
if (hasCtrl && event.key === Qt.Key_S) {
editorView.saveEntry(hasShift ? "close" : "history");
event.accepted = true;
return;
}
if (hasCtrl && hasShift && event.key === Qt.Key_V) {
editorView.saveEntry("paste");
event.accepted = true;
return;
}
} }
} }
} }
@@ -435,16 +489,17 @@ DankModal {
text: I18n.tr("Edit clipboard text") text: I18n.tr("Edit clipboard text")
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: Theme.outlineButton color: Theme.outlineButton
anchors.left: editField.left anchors.left: editScroll.left
anchors.right: editField.right anchors.right: editScroll.right
anchors.top: editField.top anchors.top: editScroll.top
anchors.bottom: editField.bottom anchors.bottom: editScroll.bottom
visible: editField.text.length === 0 && !editField.activeFocus visible: editField.text.length === 0 && !editField.activeFocus
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
} }
} }
Row { Row {
id: editorActions
width: parent.width width: parent.width
spacing: Theme.spacingS spacing: Theme.spacingS