MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Field_CharEvent

Function Field_CharEvent

code/client/cl_keys.cpp:584–656  ·  view source on GitHub ↗

================== Field_CharEvent ================== */

Source from the content-addressed store, hash-verified

582==================
583*/
584void Field_CharEvent( field_t *edit, int ch ) {
585 int len;
586
587 if ( ch == 'v' - 'a' + 1 ) { // ctrl-v is paste
588 Field_Paste( edit );
589 return;
590 }
591
592 if ( ch == 'c' - 'a' + 1 ) { // ctrl-c clears the field
593 Field_Clear( edit );
594 return;
595 }
596
597 len = strlen( edit->buffer );
598
599 if ( ch == 'h' - 'a' + 1 ) { // ctrl-h is backspace
600 if ( edit->cursor > 0 ) {
601 memmove( edit->buffer + edit->cursor - 1,
602 edit->buffer + edit->cursor, len + 1 - edit->cursor );
603 edit->cursor--;
604 if ( edit->cursor < edit->scroll )
605 {
606 edit->scroll--;
607 }
608 }
609 return;
610 }
611
612 if ( ch == 'a' - 'a' + 1 ) { // ctrl-a is home
613 edit->cursor = 0;
614 edit->scroll = 0;
615 return;
616 }
617
618 if ( ch == 'e' - 'a' + 1 ) { // ctrl-e is end
619 edit->cursor = len;
620 edit->scroll = edit->cursor - edit->widthInChars;
621 return;
622 }
623
624 //
625 // ignore any other non printable chars
626 //
627 if ( ch < 32 ) {
628 return;
629 }
630
631 if ( kg.key_overstrikeMode ) {
632 // - 2 to leave room for the leading slash and trailing \0
633 if ( edit->cursor == MAX_EDIT_LINE - 2 )
634 return;
635 edit->buffer[edit->cursor] = ch;
636 edit->cursor++;
637 } else { // insert mode
638 // - 2 to leave room for the leading slash and trailing \0
639 if ( len == MAX_EDIT_LINE - 2 ) {
640 return; // all full
641 }

Callers 2

Field_PasteFunction · 0.70
CL_CharEventFunction · 0.70

Calls 2

Field_PasteFunction · 0.70
Field_ClearFunction · 0.50

Tested by

no test coverage detected