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

Function Field_KeyDownEvent

code/client/cl_keys.cpp:516–577  ·  view source on GitHub ↗

================= Field_KeyDownEvent Performs the basic line editing functions for the console, in-game talk, and menu fields Key events are used for non-printable characters, others are gotten from char events. ================= */

Source from the content-addressed store, hash-verified

514=================
515*/
516void Field_KeyDownEvent( field_t *edit, int key ) {
517 int len;
518
519 // shift-insert is paste
520 if ( ( key == A_INSERT ) && kg.keys[A_SHIFT].down )
521 {
522 Field_Paste( edit );
523 return;
524 }
525
526 len = strlen( edit->buffer );
527
528 if ( key == A_DELETE ) {
529 if ( edit->cursor < len ) {
530 memmove( edit->buffer + edit->cursor,
531 edit->buffer + edit->cursor + 1, len - edit->cursor );
532 }
533 return;
534 }
535
536 if ( key == A_CURSOR_RIGHT )
537 {
538 if ( edit->cursor < len ) {
539 edit->cursor++;
540 }
541 if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len )
542 {
543 edit->scroll++;
544 }
545 return;
546 }
547
548 if ( key == A_CURSOR_LEFT )
549 {
550 if ( edit->cursor > 0 ) {
551 edit->cursor--;
552 }
553 if ( edit->cursor < edit->scroll )
554 {
555 edit->scroll--;
556 }
557 return;
558 }
559
560 if ( key == A_HOME || ( keynames[key].lower == 'a' && kg.keys[A_CTRL].down ) )
561 {
562 edit->cursor = 0;
563 return;
564 }
565
566 if ( key == A_END || ( keynames[key].lower == 'e' && kg.keys[A_CTRL].down ) )
567 {
568 edit->cursor = len;
569 return;
570 }
571
572 if ( key == A_INSERT )
573 {

Callers 1

Console_KeyFunction · 0.70

Calls 1

Field_PasteFunction · 0.70

Tested by

no test coverage detected