MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / OnKeyPressed

Method OnKeyPressed

Source/CodeEntry.cpp:754–993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

752}
753
754void CodeEntry::OnKeyPressed(int key, bool isRepeat)
755{
756 if (key == juce::KeyPress::backspaceKey)
757 {
758 if (mCaretPosition != mCaretPosition2)
759 {
760 RemoveSelectedText();
761 }
762 else if (mCaretPosition > 0)
763 {
764 MoveCaret(mCaretPosition - 1, false);
765 if (mCaretPosition < mString.length() - 1)
766 UpdateString(mString.substr(0, mCaretPosition) + mString.substr(mCaretPosition + 1));
767 else
768 UpdateString(mString.substr(0, mCaretPosition));
769 }
770 }
771 else if (key == juce::KeyPress::deleteKey)
772 {
773 if (mCaretPosition != mCaretPosition2)
774 {
775 RemoveSelectedText();
776 }
777 else
778 {
779 if (mCaretPosition == 0)
780 UpdateString(mString.substr(1));
781 if (mCaretPosition < mString.length() - 1)
782 UpdateString(mString.substr(0, mCaretPosition) + mString.substr(mCaretPosition + 1));
783 }
784 }
785 else if (key == OF_KEY_TAB)
786 {
787 if (mCaretPosition != mCaretPosition2 || (GetKeyModifiers() & kModifier_Shift))
788 {
789 ShiftLines(GetKeyModifiers() & kModifier_Shift);
790 }
791 else
792 {
793 ofVec2f coords = GetCaretCoords(mCaretPosition);
794 int spacesNeeded = kTabSize - (int)coords.x % kTabSize;
795 std::string tab;
796 for (int i = 0; i < spacesNeeded; ++i)
797 tab += " ";
798 AddString(tab);
799 }
800 }
801 else if (key == ']' && GetKeyModifiers() == kModifier_Command)
802 {
803 ShiftLines(false);
804 }
805 else if (key == '[' && GetKeyModifiers() == kModifier_Command)
806 {
807 ShiftLines(true);
808 }
809 else if (key == OF_KEY_ESC)
810 {
811 if (IsAutocompleteShowing())

Callers 1

KeyPressedMethod · 0.45

Calls 7

GetKeyModifiersFunction · 0.85
lengthMethod · 0.80
sizeMethod · 0.80
PathMethod · 0.80
CopyTextToClipboardMethod · 0.80
ExecuteCodeMethod · 0.80
ExecuteBlockMethod · 0.80

Tested by

no test coverage detected