| 3733 | } |
| 3734 | |
| 3735 | void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end) |
| 3736 | { |
| 3737 | const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0; |
| 3738 | const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)strlen(new_text); |
| 3739 | if (new_text_len + BufTextLen >= BufSize) |
| 3740 | { |
| 3741 | if (!is_resizable) |
| 3742 | return; |
| 3743 | |
| 3744 | // Contrary to STB_TEXTEDIT_INSERTCHARS() this is working in the UTF8 buffer, hence the mildly similar code (until we remove the U16 buffer altogether!) |
| 3745 | ImGuiContext& g = *GImGui; |
| 3746 | ImGuiInputTextState* edit_state = &g.InputTextState; |
| 3747 | IM_ASSERT(edit_state->ID != 0 && g.ActiveId == edit_state->ID); |
| 3748 | IM_ASSERT(Buf == edit_state->TextA.Data); |
| 3749 | int new_buf_size = BufTextLen + ImClamp(new_text_len * 4, 32, ImMax(256, new_text_len)) + 1; |
| 3750 | edit_state->TextA.reserve(new_buf_size + 1); |
| 3751 | Buf = edit_state->TextA.Data; |
| 3752 | BufSize = edit_state->BufCapacityA = new_buf_size; |
| 3753 | } |
| 3754 | |
| 3755 | if (BufTextLen != pos) |
| 3756 | memmove(Buf + pos + new_text_len, Buf + pos, (size_t)(BufTextLen - pos)); |
| 3757 | memcpy(Buf + pos, new_text, (size_t)new_text_len * sizeof(char)); |
| 3758 | Buf[BufTextLen + new_text_len] = '\0'; |
| 3759 | |
| 3760 | if (CursorPos >= pos) |
| 3761 | CursorPos += new_text_len; |
| 3762 | SelectionStart = SelectionEnd = CursorPos; |
| 3763 | BufDirty = true; |
| 3764 | BufTextLen += new_text_len; |
| 3765 | } |
| 3766 | |
| 3767 | // Return false to discard a character. |
| 3768 | static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source) |
no test coverage detected