reduce manual updates by aliasing stickypadContents to input area's text

This commit is contained in:
end-4
2025-11-14 11:05:50 +01:00
parent f8ffe5e63f
commit a3cb292fe9
@@ -12,7 +12,7 @@ import qs.modules.ii.overlay
OverlayBackground { OverlayBackground {
id: root id: root
property string stickypadContents: "" property alias stickypadContents: stickypadInput.text
property bool pendingReload: false property bool pendingReload: false
property var copylistEntries: [] property var copylistEntries: []
property string lastParsedCopylistText: "" property string lastParsedCopylistText: ""
@@ -27,22 +27,21 @@ OverlayBackground {
function saveStickypad() { function saveStickypad() {
if (!stickypadInput) if (!stickypadInput)
return; return;
stickypadContents = stickypadInput.text; stickypadFile.setText(root.stickypadContents);
stickypadFile.setText(stickypadContents);
} }
function focusStickypadAtEnd() { function focusStickypadAtEnd() {
if (!stickypadInput) if (!stickypadInput)
return; return;
stickypadInput.forceActiveFocus(); stickypadInput.forceActiveFocus();
const endPos = stickypadInput.text.length; const endPos = root.stickypadContents.length;
applySelection(endPos, endPos); applySelection(endPos, endPos);
} }
function applySelection(cursorPos, anchorPos) { function applySelection(cursorPos, anchorPos) {
if (!stickypadInput) if (!stickypadInput)
return; return;
const textLength = stickypadInput.text.length; const textLength = root.stickypadContents.length;
const cursor = Math.max(0, Math.min(cursorPos, textLength)); const cursor = Math.max(0, Math.min(cursorPos, textLength));
const anchor = Math.max(0, Math.min(anchorPos, textLength)); const anchor = Math.max(0, Math.min(anchorPos, textLength));
stickypadInput.select(anchor, cursor); stickypadInput.select(anchor, cursor);
@@ -64,7 +63,7 @@ OverlayBackground {
function updateCopylistEntries() { function updateCopylistEntries() {
if (!stickypadInput) if (!stickypadInput)
return; return;
const textValue = stickypadInput.text; const textValue = root.stickypadContents;
if (!textValue || textValue.length === 0) { if (!textValue || textValue.length === 0) {
lastParsedCopylistText = ""; lastParsedCopylistText = "";
parsedCopylistLines = []; parsedCopylistLines = [];
@@ -175,9 +174,7 @@ OverlayBackground {
} }
root.scheduleCopylistUpdate(true); root.scheduleCopylistUpdate(true);
} }
onCursorPositionChanged: root.scheduleCopylistUpdate()
onSelectionStartChanged: root.scheduleCopylistUpdate()
onSelectionEndChanged: root.scheduleCopylistUpdate()
onHeightChanged: root.scheduleCopylistUpdate(true) onHeightChanged: root.scheduleCopylistUpdate(true)
onContentHeightChanged: root.scheduleCopylistUpdate(true) onContentHeightChanged: root.scheduleCopylistUpdate(true)
} }
@@ -291,28 +288,26 @@ OverlayBackground {
id: stickypadFile id: stickypadFile
path: Qt.resolvedUrl(Directories.stickypadPath) path: Qt.resolvedUrl(Directories.stickypadPath)
onLoaded: { onLoaded: {
stickypadContents = stickypadFile.text(); root.stickypadContents = stickypadFile.text();
if (stickypadInput && stickypadInput.text !== stickypadContents) { if (root.stickypadContents !== root.stickypadContents) {
const previousCursor = stickypadInput.cursorPosition; const previousCursor = stickypadInput.cursorPosition;
const previousAnchor = stickypadInput.selectionStart; const previousAnchor = stickypadInput.selectionStart;
stickypadInput.text = stickypadContents; root.stickypadContents = root.stickypadContents;
applySelection(previousCursor, previousAnchor); applySelection(previousCursor, previousAnchor);
} }
if (pendingReload) { if (pendingReload) {
pendingReload = false; pendingReload = false;
Qt.callLater(focusStickypadAtEnd); Qt.callLater(root.focusStickypadAtEnd);
} }
Qt.callLater(root.updateCopylistEntries); Qt.callLater(root.updateCopylistEntries);
} }
onLoadFailed: error => { onLoadFailed: error => {
if (error === FileViewError.FileNotFound) { if (error === FileViewError.FileNotFound) {
stickypadContents = ""; root.stickypadContents = "";
stickypadFile.setText(stickypadContents); stickypadFile.setText(root.stickypadContents);
if (stickypadInput)
stickypadInput.text = stickypadContents;
if (pendingReload) { if (pendingReload) {
pendingReload = false; pendingReload = false;
Qt.callLater(focusStickypadAtEnd); Qt.callLater(root.focusStickypadAtEnd);
} }
Qt.callLater(root.updateCopylistEntries); Qt.callLater(root.updateCopylistEntries);
} else { } else {