================== Field_CharEvent ================== */
| 582 | ================== |
| 583 | */ |
| 584 | void 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 | } |
no test coverage detected