diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index 86ea428..9320de2 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -134,7 +134,7 @@ struct Editor::Impl : EditorController::Receiver, SValueMenu *scalaRootOctaveSlider_ = nullptr; CTextLabel* scalaRootKeyLabel_ = nullptr; SValueMenu* tuningFrequencyDropdown_ = nullptr; - CTextEdit* tuningFrequencyEdit_ = nullptr; + STextEdit* tuningFrequencyEdit_ = nullptr; CTextLabel* tuningFrequencyLabel_ = nullptr; CControl *stretchedTuningSlider_ = nullptr; CTextLabel* stretchedTuningLabel_ = nullptr; @@ -1114,7 +1114,7 @@ void Editor::Impl::createFrameContents() }; auto createTextEdit = [this, &palette] (const CRect& bounds, int tag, const char* label, CHoriTxtAlign align, int fontsize) { - auto* edit = new CTextEdit(bounds, this, tag, label, nullptr); + auto* edit = new STextEdit(bounds, this, tag, label, nullptr); auto font = makeOwned("Roboto", fontsize); edit->setFont(font); edit->setHoriAlign(align); diff --git a/plugins/editor/src/editor/GUIComponents.cpp b/plugins/editor/src/editor/GUIComponents.cpp index 6b2a6dd..aa8afb9 100644 --- a/plugins/editor/src/editor/GUIComponents.cpp +++ b/plugins/editor/src/editor/GUIComponents.cpp @@ -1348,3 +1348,36 @@ void SPlaceHolder::draw(CDrawContext* dc) dc->drawLine(bounds.getTopLeft(), bounds.getBottomRight()); dc->drawLine(bounds.getTopRight(), bounds.getBottomLeft()); } + +STextEdit::STextEdit( + const CRect& size, + IControlListener* listener, + int32_t tag, + UTF8StringPtr txt, + CBitmap* background, + const int32_t style) + : CTextEdit(size, listener, tag, txt, background, style) +{ +} + +void STextEdit::onKeyboardEvent(KeyboardEvent &event) +{ + if (!platformControl || event.type != EventType::KeyDown) + return; + + if (event.virt == VirtualKey::Escape) + { + bWasReturnPressed = false; + platformControl->setText (text); + getFrame ()->setFocusView (nullptr); + looseFocus (); + event.consumed = true; + } + else if (event.virt == VirtualKey::Return || event.virt == VirtualKey::Enter) + { + bWasReturnPressed = true; + getFrame ()->setFocusView (nullptr); + looseFocus (); + event.consumed = true; + } +} diff --git a/plugins/editor/src/editor/GUIComponents.h b/plugins/editor/src/editor/GUIComponents.h index 124ab24..9e56ece 100644 --- a/plugins/editor/src/editor/GUIComponents.h +++ b/plugins/editor/src/editor/GUIComponents.h @@ -236,6 +236,20 @@ private: bool inactive_ { false }; }; +/// CTextEdit control that can use Enter key as Return +class STextEdit: public CTextEdit { +public: + STextEdit( + const CRect& size, + IControlListener* listener, + int32_t tag, + UTF8StringPtr txt = nullptr, + CBitmap* background = nullptr, + const int32_t style = 0 + ); + void onKeyboardEvent(KeyboardEvent& event) override; +}; + /// class SStyledKnob : public CKnobBase { public: