Fix field and text area defaultText binding

Break the binding when the field is focused, recreate it when focus is
lost, properly recreate it when using reset() function.
This commit is contained in:
miruka 2020-06-03 03:41:30 -04:00
parent a6529b040c
commit 9f51b3c1ca
2 changed files with 8 additions and 2 deletions

View File

@ -19,7 +19,7 @@ TextArea {
property alias backgroundColor: textAreaBackground.color property alias backgroundColor: textAreaBackground.color
function reset() { clear(); text = defaultText } function reset() { clear(); text = Qt.binding(() => defaultText) }
function insertAtCursor(text) { insert(cursorPosition, text) } function insertAtCursor(text) { insert(cursorPosition, text) }
@ -52,6 +52,9 @@ TextArea {
textArea.cursorPosition = text.length textArea.cursorPosition = text.length
} }
onActiveFocusChanged:
text = activeFocus || changed ? text : Qt.binding(() => defaultText)
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)
Keys.onPressed: if ( Keys.onPressed: if (

View File

@ -39,6 +39,9 @@ TextField {
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)
onActiveFocusChanged:
text = activeFocus || changed ? text : Qt.binding(() => defaultText)
Keys.onPressed: if ( Keys.onPressed: if (
event.modifiers & Qt.AltModifier || event.modifiers & Qt.AltModifier ||
event.modifiers & Qt.MetaModifier event.modifiers & Qt.MetaModifier
@ -67,7 +70,7 @@ TextField {
readonly property bool changed: text !== defaultText readonly property bool changed: text !== defaultText
function reset() { clear(); text = defaultText } function reset() { clear(); text = Qt.binding(() => defaultText)}
Binding on color { Binding on color {