InputText: fixed an infinite loop error happening if a custom input text callback modifies/clear BufTextLen before calling InsertChars(). (#8994, #3237)

+ misc comments.
This commit is contained in:
ocornut
2025-10-08 19:00:34 +02:00
parent bee2720faa
commit 2b770a029b
4 changed files with 12 additions and 5 deletions

View File

@@ -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()