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:
parent
2545ba6c00
commit
82bcc29475
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user