From 82bcc29475c6299e77498d13a3ff6a15716a1935 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 3 Sep 2020 18:27:31 -0400 Subject: [PATCH] Field/area: insertAtCursor() when restoring text Instead of assigning to `text` directly, which kills editing history and has worse performance. --- src/gui/Base/HTextArea.qml | 5 +---- src/gui/Base/HTextField.qml | 14 +++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) 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)