Fixed InputText() bug with ImGuiInputTextFlags_EnterReturnsTrue (in nav branch only) (#787). Thanks @Grouflon

This commit is contained in:
omar 2017-08-22 19:43:49 +08:00
parent bea06117bb
commit f3ab5e6252
1 changed files with 5 additions and 1 deletions

View File

@ -8932,7 +8932,11 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
value_changed = true; 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 // 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 // Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer