Skip to content

Commit

Permalink
Fixed InputText() bug with ImGuiInputTextFlags_EnterReturnsTrue (in n…
Browse files Browse the repository at this point in the history
…av branch only) (#787). Thanks @Grouflon
  • Loading branch information
ocornut committed Aug 22, 2017
1 parent bea0611 commit f3ab5e6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3ab5e6

Please sign in to comment.