@@ -6,6 +6,7 @@ TextField {
66
77 // evaluated numeric value (NaN if invalid)
88 // It helps keeping the connection that text has so that we don't loose ability to undo/reset
9+ property bool textChanged: false
910 property real evaluatedValue: 0
1011
1112 property bool hasExprError: false
@@ -39,7 +40,7 @@ TextField {
3940 _res = _res .toFixed (decimals)
4041 return _res
4142 } else {
42- console .error (" Error : Expression" , _text, " is invalid" )
43+ console .error (" Error: Expression" , _text, " is invalid" )
4344 return NaN
4445 }
4546 }
@@ -62,6 +63,7 @@ TextField {
6263 evaluatedValue = previousEvaluatedValue
6364 raiseError ()
6465 }
66+ textChanged = false
6567 }
6668
6769 // onAccepted and onEditingFinished will break the bindings to text
@@ -70,29 +72,37 @@ TextField {
7072 // No need to restore the binding if the expression has an error because we don't break it
7173
7274 onAccepted: {
73- updateExpression ()
74- if (! hasExprError && ! isNaN (evaluatedValue)) {
75- // Commit the result value to the text field
76- if (isInt)
77- root .text = Number (evaluatedValue).toFixed (0 )
78- else
79- root .text = Number (evaluatedValue).toFixed (decimals)
75+ if (textChanged)
76+ {
77+ updateExpression ()
78+ if (! hasExprError && ! isNaN (evaluatedValue)) {
79+ // Commit the result value to the text field
80+ if (isInt)
81+ root .text = Number (evaluatedValue).toFixed (0 )
82+ else
83+ root .text = Number (evaluatedValue).toFixed (decimals)
84+ }
8085 }
8186 }
8287
8388 onEditingFinished: {
84- updateExpression ()
85- if (! hasExprError && ! isNaN (evaluatedValue)) {
86- if (isInt)
87- root .text = Number (evaluatedValue).toFixed (0 )
88- else
89- root .text = Number (evaluatedValue).toFixed (decimals)
89+ if (textChanged)
90+ {
91+ updateExpression ()
92+ if (! hasExprError && ! isNaN (evaluatedValue)) {
93+ if (isInt)
94+ root .text = Number (evaluatedValue).toFixed (0 )
95+ else
96+ root .text = Number (evaluatedValue).toFixed (decimals)
97+ }
9098 }
9199 }
92100
93101 onTextChanged: {
94102 if (! activeFocus) {
95103 refreshStatus ()
104+ } else {
105+ textChanged = true
96106 }
97107 }
98108
0 commit comments