diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 496bf1d9f..9c5b50988 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,11 @@ Other Changes: The grip is not visible before hovering to reduce clutter. - InputText: fixed single-line InputText() not applying fine character clipping properly (regression in 1.92.3). (#8967) [@Cyphall] +- InputText: fixed an infinite loop error happening if a custom input text + callback modifies/clear BufTextLen before calling InsertChars(). + (regression from 1.92.3). Note that this never really worked correctly, but + previously it would only temporary wreck cursor position, and since 1.92.3 it + would go in an infinite loop. (#8994, #3237) - Style: added ImGuiCol_UnsavedMarker, color of the unsaved document marker when using ImGuiWindowFlags_UnsavedDocument/ImGuiTabItemFlags_UnsavedDocument. (#8983) - IO: added ImGuiPlatformIO::ClearPlatformHandlers(), ClearRendererHandlers() diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 3a6bcf5a5..dec1bad40 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4804,7 +4804,7 @@ static void DemoWindowLayout() ImGui::SameLine(); scroll_to_off |= ImGui::Button("Scroll Offset"); - bool scroll_to_pos = ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, FLT_MAX, "X/Y = %.0f px");; + bool scroll_to_pos = ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, FLT_MAX, "X/Y = %.0f px"); ImGui::SameLine(); scroll_to_pos |= ImGui::Button("Scroll To Pos"); ImGui::PopItemWidth(); diff --git a/imgui_internal.h b/imgui_internal.h index e65cbcab7..1510271a0 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2484,7 +2484,7 @@ struct ImGuiContext ImGuiWindow* LogWindow; ImFileHandle LogFile; // If != NULL log to stdout/ file ImGuiTextBuffer LogBuffer; // Accumulation buffer when log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. - const char* LogNextPrefix; + const char* LogNextPrefix; // See comment in LogSetNextTextDecoration(): doesn't copy underlying data, use carefully! const char* LogNextSuffix; float LogLinePosY; bool LogLineFirstItem; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 45a4dcf62..a3a4ae1cf 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3941,6 +3941,7 @@ static ImVec2 InputTextCalcTextSize(ImGuiContext* ctx, const char* text_begin, c { ImGuiContext& g = *ctx; ImGuiInputTextState* obj = &g.InputTextState; + IM_ASSERT(text_end_display >= text_begin && text_end_display <= text_end); return ImFontCalcTextSizeEx(g.Font, g.FontSize, FLT_MAX, obj->WrapWidth, text_begin, text_end_display, text_end, out_remaining, out_offset, flags); } @@ -4321,11 +4322,12 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons memcpy(Buf + pos, new_text, (size_t)new_text_len * sizeof(char)); Buf[BufTextLen + new_text_len] = '\0'; - if (CursorPos >= pos) - CursorPos += new_text_len; - SelectionStart = SelectionEnd = CursorPos; BufDirty = true; BufTextLen += new_text_len; + if (CursorPos >= pos) + CursorPos += new_text_len; + CursorPos = ImClamp(CursorPos, 0, BufTextLen); + SelectionStart = SelectionEnd = CursorPos; } void ImGui::PushPasswordFont()