@@ -82,27 +82,11 @@ class DraggableNumber : public Label
8282 void editorHidden (Label*, TextEditor& editor) override
8383 {
8484 auto text = editor.getText ();
85- double newValue;
86- if (!text.containsOnly (" 0123456789." ))
87- {
88- String parseError;
89- try {
90- newValue = Expression (text, parseError).evaluate ();
91- } catch (...) {
92- newValue = 0 .0f ;
93- }
94-
95- if (!parseError.isEmpty ())
96- {
97- newValue = 0 .0f ;
98- }
99- }
100- else {
101- newValue = text.getDoubleValue ();
102- }
85+ double newValue = parseExpression (text);
10386
10487 onInteraction (hasKeyboardFocus (false ));
10588 setValue (newValue, dontSendNotification);
89+ editor.setText (getText (), dontSendNotification);
10690 decimalDrag = 0 ;
10791 dragEnd ();
10892 }
@@ -554,6 +538,41 @@ class DraggableNumber : public Label
554538
555539 return text;
556540 }
541+
542+ double parseExpression (String const & expression)
543+ {
544+ if (expression.containsOnly (" 0123456789." ))
545+ {
546+ return expression.getDoubleValue ();
547+ }
548+ else {
549+ String parseError;
550+ try {
551+ return Expression (expression, parseError).evaluate ();
552+ } catch (...) {
553+ return 0 .0f ;
554+ }
555+
556+ if (!parseError.isEmpty ())
557+ {
558+ return 0 .0f ;
559+ }
560+ }
561+
562+ return 0 .0f ;
563+ }
564+
565+ void textEditorFocusLost (TextEditor& editor) override
566+ {
567+ textEditorReturnKeyPressed (editor);
568+ }
569+
570+ void textEditorReturnKeyPressed (TextEditor& editor) override
571+ {
572+ auto text = editor.getText ();
573+ double newValue = parseExpression (text);
574+ setValue (newValue);
575+ }
557576};
558577
559578struct DraggableListNumber : public DraggableNumber {
0 commit comments