From 64172685d62c6abfdf481a23f3d366ce7dec72d8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 3 Jul 2023 11:58:17 +0200 Subject: [PATCH] InputText: ImGuiInputTextCallbackData::InsertChars() accept (NULL,NULL) range, in order to conform to common idioms. (#6565, #6566, #3615) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 403935a6e..a4e7accef 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -88,6 +88,8 @@ Other changes: - CollapsingHeader/TreeNode: Fixed text padding when using _Framed+_Leaf flags. (#6549) [@BobbyAnguelov] - InputText: Fixed not returning true when buffer is cleared while using the ImGuiInputTextFlags_EscapeClearsAll flag. (#5688, #2620) +- InputText: ImGuiInputTextCallbackData::InsertChars() accept (NULL,NULL) range, in order to conform + to common idioms (e.g. passing .data(), .data() + .size() from a null string). (#6565, #6566, #3615) - Combo: Made simple/legacy Combo() function not returns true when picking already selected item. This is consistent with other widgets. If you need something else, you can use BeginCombo(). (#1182) - Clipper: Rework inner logic to allow functioning with a zero-clear constructor. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 67e5d3acf..9704f5e24 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3873,6 +3873,10 @@ void ImGuiInputTextCallbackData::DeleteChars(int pos, int bytes_count) void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end) { + // Accept null ranges + if (new_text == new_text_end) + return; + const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0; const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)strlen(new_text); if (new_text_len + BufTextLen >= BufSize)