MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / stb_textedit_key

Function stb_textedit_key

KBotExt/imgui/imstb_textedit.h:716–1098  ·  view source on GitHub ↗

API key: process a keyboard input

Source from the content-addressed store, hash-verified

714
715// API key: process a keyboard input
716static void stb_textedit_key(STB_TEXTEDIT_STRING* str, STB_TexteditState* state, STB_TEXTEDIT_KEYTYPE key)
717{
718retry:
719 switch (key) {
720 default: {
721 int c = STB_TEXTEDIT_KEYTOTEXT(key);
722 if (c > 0) {
723 STB_TEXTEDIT_CHARTYPE ch = (STB_TEXTEDIT_CHARTYPE)c;
724
725 // can't add newline in single-line mode
726 if (c == '\n' && state->single_line)
727 break;
728
729 if (state->insert_mode && !STB_TEXT_HAS_SELECTION(state) && state->cursor < STB_TEXTEDIT_STRINGLEN(str)) {
730 stb_text_makeundo_replace(str, state, state->cursor, 1, 1);
731 STB_TEXTEDIT_DELETECHARS(str, state->cursor, 1);
732 if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
733 ++state->cursor;
734 state->has_preferred_x = 0;
735 }
736 }
737 else {
738 stb_textedit_delete_selection(str, state); // implicitly clamps
739 if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
740 stb_text_makeundo_insert(state, state->cursor, 1);
741 ++state->cursor;
742 state->has_preferred_x = 0;
743 }
744 }
745 }
746 break;
747 }
748
749#ifdef STB_TEXTEDIT_K_INSERT
750 case STB_TEXTEDIT_K_INSERT:
751 state->insert_mode = !state->insert_mode;
752 break;
753#endif
754
755 case STB_TEXTEDIT_K_UNDO:
756 stb_text_undo(str, state);
757 state->has_preferred_x = 0;
758 break;
759
760 case STB_TEXTEDIT_K_REDO:
761 stb_text_redo(str, state);
762 state->has_preferred_x = 0;
763 break;
764
765 case STB_TEXTEDIT_K_LEFT:
766 // if currently there's a selection, move cursor to start of selection
767 if (STB_TEXT_HAS_SELECTION(state))
768 stb_textedit_move_to_first(state);
769 else
770 if (state->cursor > 0)
771 --state->cursor;
772 state->has_preferred_x = 0;
773 break;

Callers 1

OnKeyPressedMethod · 0.85

Calls 15

STB_TEXTEDIT_KEYTOTEXTFunction · 0.85
STB_TEXTEDIT_STRINGLENFunction · 0.85
STB_TEXTEDIT_DELETECHARSFunction · 0.85
STB_TEXTEDIT_INSERTCHARSFunction · 0.85
stb_text_makeundo_insertFunction · 0.85
stb_text_undoFunction · 0.85
stb_text_redoFunction · 0.85
stb_textedit_clampFunction · 0.85

Tested by

no test coverage detected