MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / stb_textedit_replace

Function stb_textedit_replace

imgui_tiny_app/imgui/imgui_widgets.cpp:4256–4271  ·  view source on GitHub ↗

stb_textedit internally allows for a single undo record to do addition and deletion, but somehow, calling the stb_textedit_paste() function creates two separate records, so we perform it manually. (FIXME: Report to nothings/stb?)

Source from the content-addressed store, hash-verified

4254// stb_textedit internally allows for a single undo record to do addition and deletion, but somehow, calling
4255// the stb_textedit_paste() function creates two separate records, so we perform it manually. (FIXME: Report to nothings/stb?)
4256static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* state, const IMSTB_TEXTEDIT_CHARTYPE* text, int text_len)
4257{
4258 stb_text_makeundo_replace(str, state, 0, str->TextLen, text_len);
4259 ImStb::STB_TEXTEDIT_DELETECHARS(str, 0, str->TextLen);
4260 state->cursor = state->select_start = state->select_end = 0;
4261 if (text_len <= 0)
4262 return;
4263 int text_len_inserted = ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len);
4264 if (text_len_inserted > 0)
4265 {
4266 state->cursor = state->select_start = state->select_end = text_len;
4267 state->has_preferred_x = 0;
4268 return;
4269 }
4270 IM_ASSERT(0); // Failed to insert character, normally shouldn't happen because of how we currently use stb_textedit_replace()
4271}
4272
4273} // namespace ImStb
4274

Callers 1

InputTextExMethod · 0.85

Calls 3

STB_TEXTEDIT_DELETECHARSFunction · 0.85
STB_TEXTEDIT_INSERTCHARSFunction · 0.85

Tested by

no test coverage detected