@@ -678,18 +678,32 @@ void SliceControlBar::mouseDoubleClick (const juce::MouseEvent& e)
678678 textEditor->selectAll ();
679679 textEditor->grabKeyboardFocus ();
680680
681- textEditor->onReturnKey = [this ] {
682- if (textEditor == nullptr ) return ;
683- int val = juce::jlimit (0 , 127 , textEditor->getText ().getIntValue ());
681+ juce::Component::SafePointer<SliceControlBar> safeThis (this );
682+ textEditor->onReturnKey = [safeThis] {
683+ if (safeThis == nullptr ) return ;
684+ auto & self = *safeThis;
685+ if (self.textEditor == nullptr ) return ;
686+ int val = juce::jlimit (0 , 127 , self.textEditor ->getText ().getIntValue ());
684687 IntersectProcessor::Command cmd;
685688 cmd.type = IntersectProcessor::CmdSetRootNote;
686689 cmd.intParam1 = val;
687- processor.pushCommand (cmd);
688- textEditor.reset ();
689- repaint ();
690+ self.processor .pushCommand (cmd);
691+ self.textEditor ->onFocusLost = nullptr ;
692+ self.textEditor .reset ();
693+ self.repaint ();
694+ };
695+ textEditor->onEscapeKey = [safeThis] {
696+ if (safeThis == nullptr ) return ;
697+ safeThis->textEditor ->onFocusLost = nullptr ;
698+ safeThis->textEditor .reset ();
699+ safeThis->repaint ();
700+ };
701+ textEditor->onFocusLost = [safeThis] {
702+ if (safeThis == nullptr ) return ;
703+ safeThis->textEditor ->onFocusLost = nullptr ;
704+ safeThis->textEditor .reset ();
705+ safeThis->repaint ();
690706 };
691- textEditor->onEscapeKey = [this ] { textEditor.reset (); repaint (); };
692- textEditor->onFocusLost = [this ] { textEditor.reset (); repaint (); };
693707 return ;
694708 }
695709
@@ -806,9 +820,13 @@ void SliceControlBar::showTextEditor (const ParamCell& cell, float currentValue)
806820 float minV = cell.minVal ;
807821 float maxV = cell.maxVal ;
808822
809- textEditor->onReturnKey = [this , fieldId, minV, maxV] {
810- if (textEditor == nullptr ) return ;
811- float val = textEditor->getText ().getFloatValue ();
823+ juce::Component::SafePointer<SliceControlBar> safeThis (this );
824+
825+ textEditor->onReturnKey = [safeThis, fieldId, minV, maxV] {
826+ if (safeThis == nullptr ) return ;
827+ auto & self = *safeThis;
828+ if (self.textEditor == nullptr ) return ;
829+ float val = self.textEditor ->getText ().getFloatValue ();
812830
813831 // Convert ms to seconds for ATK/DEC/REL, percent to fraction for SUS
814832 if (fieldId == IntersectProcessor::FieldAttack ||
@@ -825,19 +843,26 @@ void SliceControlBar::showTextEditor (const ParamCell& cell, float currentValue)
825843 cmd.type = IntersectProcessor::CmdSetSliceParam;
826844 cmd.intParam1 = fieldId;
827845 cmd.floatParam1 = val;
828- processor.pushCommand (cmd);
829- textEditor.reset ();
830- repaint ();
846+ self.processor .pushCommand (cmd);
847+ self.textEditor ->onFocusLost = nullptr ;
848+ self.textEditor .reset ();
849+ self.repaint ();
831850 };
832851
833- textEditor->onEscapeKey = [this ] {
834- textEditor.reset ();
835- repaint ();
852+ textEditor->onEscapeKey = [safeThis] {
853+ if (safeThis == nullptr ) return ;
854+ auto & self = *safeThis;
855+ self.textEditor ->onFocusLost = nullptr ;
856+ self.textEditor .reset ();
857+ self.repaint ();
836858 };
837859
838- textEditor->onFocusLost = [this ] {
839- textEditor.reset ();
840- repaint ();
860+ textEditor->onFocusLost = [safeThis] {
861+ if (safeThis == nullptr ) return ;
862+ auto & self = *safeThis;
863+ self.textEditor ->onFocusLost = nullptr ;
864+ self.textEditor .reset ();
865+ self.repaint ();
841866 };
842867}
843868
0 commit comments