API paste: replace existing selection with passed-in text
| 693 | |
| 694 | // API paste: replace existing selection with passed-in text |
| 695 | static int stb_textedit_paste_internal(STB_TEXTEDIT_STRING* str, STB_TexteditState* state, STB_TEXTEDIT_CHARTYPE* text, int len) |
| 696 | { |
| 697 | // if there's a selection, the paste should delete it |
| 698 | stb_textedit_clamp(str, state); |
| 699 | stb_textedit_delete_selection(str, state); |
| 700 | // try to insert the characters |
| 701 | if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) { |
| 702 | stb_text_makeundo_insert(state, state->cursor, len); |
| 703 | state->cursor += len; |
| 704 | state->has_preferred_x = 0; |
| 705 | return 1; |
| 706 | } |
| 707 | // note: paste failure will leave deleted selection, may be restored with an undo (see https://github.com/nothings/stb/issues/734 for details) |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | #ifndef STB_TEXTEDIT_KEYTYPE |
| 712 | #define STB_TEXTEDIT_KEYTYPE int |
no test coverage detected