From f3ab5e6252ec5483fe82c6fd243cbb0caac94ff1 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 22 Aug 2017 19:43:49 +0800 Subject: [PATCH] Fixed InputText() bug with ImGuiInputTextFlags_EnterReturnsTrue (in nav branch only) (#787). Thanks @Grouflon --- imgui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 5a6947912..acefc4575 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8932,7 +8932,11 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 value_changed = true; } } - if (!cancel_edit && !clear_active_id) + + // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. + // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. Also this allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage. + bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); + if (apply_edit_back_to_user_buffer) { // Apply new value immediately - copy modified buffer back // Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer