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
// Set it only on component creation to avoid binding loops
if (! text) {
text = window.getState(this, "text", "")
cursorPosition = text.length
}
if (! text) insertAtCursor(window.getState(this, "text", ""))
}
onTextChanged: window.saveState(this)

View File

@ -29,7 +29,14 @@ TextField {
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 || ""
@ -69,10 +76,7 @@ TextField {
previousDefaultText = previousDefaultText
// Set it only on component creation to avoid binding loops
if (! text) {
text = window.getState(this, "text", "")
cursorPosition = text.length
}
if (! text) insertAtCursor(window.getState(this, "text", ""))
}
onTextChanged: window.saveState(this)