Field/area: insertAtCursor() when restoring text

Instead of assigning to `text` directly, which kills editing history and
has worse performance.
This commit is contained in:
miruka 2020-09-03 18:27:31 -04:00
parent 2545ba6c00
commit 82bcc29475
2 changed files with 10 additions and 9 deletions

View File

@ -89,10 +89,7 @@ TextArea {
previousDefaultText = previousDefaultText previousDefaultText = previousDefaultText
// Set it only on component creation to avoid binding loops // Set it only on component creation to avoid binding loops
if (! text) { if (! text) insertAtCursor(window.getState(this, "text", ""))
text = window.getState(this, "text", "")
cursorPosition = text.length
}
} }
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)

View File

@ -29,7 +29,14 @@ TextField {
property string previousDefaultText: "" // private property string previousDefaultText: "" // private
function reset() { clear(); text = Qt.binding(() => defaultText || "")} function reset() {
clear()
text = Qt.binding(() => defaultText || "")
}
function insertAtCursor(text) {
insert(cursorPosition, text)
}
text: defaultText || "" text: defaultText || ""
@ -69,10 +76,7 @@ TextField {
previousDefaultText = previousDefaultText previousDefaultText = previousDefaultText
// Set it only on component creation to avoid binding loops // Set it only on component creation to avoid binding loops
if (! text) { if (! text) insertAtCursor(window.getState(this, "text", ""))
text = window.getState(this, "text", "")
cursorPosition = text.length
}
} }
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)