diff --git a/src/gui/Base/HTextArea.qml b/src/gui/Base/HTextArea.qml index bdbb1099..0b85c97e 100644 --- a/src/gui/Base/HTextArea.qml +++ b/src/gui/Base/HTextArea.qml @@ -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) diff --git a/src/gui/Base/HTextField.qml b/src/gui/Base/HTextField.qml index d7605ea5..b90479ca 100644 --- a/src/gui/Base/HTextField.qml +++ b/src/gui/Base/HTextField.qml @@ -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)