Protect field/area text binding if no default text

This commit is contained in:
miruka 2020-07-01 12:10:40 -04:00
parent 4752abf6e5
commit 24e657d193
2 changed files with 14 additions and 12 deletions

View File

@ -17,8 +17,8 @@ TextArea {
property var focusItemOnTab: null
property var disabledText: null
property string defaultText: ""
readonly property bool changed: text !== defaultText
property var defaultText: null // XXX test me
readonly property bool changed: text !== (defaultText || "")
property alias backgroundColor: textAreaBackground.color
property color borderColor: theme.controls.textArea.border
@ -28,11 +28,11 @@ TextArea {
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 || ""
opacity: enabled ? 1 : theme.disabledElementsOpacity
selectByMouse: true
leftPadding: theme.spacing
@ -77,9 +77,10 @@ TextArea {
onTextChanged: window.saveState(this)
onActiveFocusChanged: text = text // Break binding
onActiveFocusChanged:
if (defaultText !== null) text = text // Break binding
onDefaultTextChanged: {
onDefaultTextChanged: if (defaultText !== null) {
if (text === previousDefaultText)
text = Qt.binding(() => defaultText)

View File

@ -5,7 +5,7 @@ import QtQuick.Controls 2.12
TextField {
id: field
text: defaultText
text: defaultText || ""
opacity: enabled ? 1 : theme.disabledElementsOpacity
selectByMouse: true
leftPadding: theme.spacing
@ -50,9 +50,10 @@ TextField {
onTextChanged: window.saveState(this)
onActiveFocusChanged: text = text // Break binding
onActiveFocusChanged:
if (defaultText !== null) text = text // Break binding
onDefaultTextChanged: {
onDefaultTextChanged: if (defaultText !== null) {
if (text === previousDefaultText)
text = Qt.binding(() => defaultText)
@ -89,13 +90,13 @@ TextField {
property color focusedBorderColor: theme.controls.textField.focusedBorder
property var disabledText: null
property string defaultText: ""
readonly property bool changed: text !== defaultText
property var defaultText: null
readonly property bool changed: text !== (defaultText || "")
property string previousDefaultText: "" // private
function reset() { clear(); text = Qt.binding(() => defaultText)}
function reset() { clear(); text = Qt.binding(() => defaultText || "")}
Binding on color {