Browse Source

InputText: do not set WantTextInputNextFrame during the frame InputText is deactivated. (#6341)

lukaasm 2 years ago
parent
commit
0948cfc19e
2 changed files with 6 additions and 2 deletions
  1. 2 0
      docs/CHANGELOG.txt
  2. 4 2
      imgui_widgets.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -44,6 +44,8 @@ Other changes:
 
 - Tables: Fixed a small miscalculation in TableHeader() leading to an empty tooltip
   showing when a sorting column has no visible name. (#6342) [@lukaasm]
+- InputText: Avoid setting io.WantTextInputNextFrame during the deactivation frame.
+  (#6341) [@lukaasm]
 - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV]
   Potentially this would facilitate switching runtime backend mid-session.
 

+ 4 - 2
imgui_widgets.cpp

@@ -4296,7 +4296,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
         // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
         // Down the line we should have a cleaner library-wide concept of Selected vs Active.
         g.ActiveIdAllowOverlap = !io.MouseDown[0];
-        g.WantTextInputNextFrame = 1;
 
         // Edit in progress
         const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->ScrollX;
@@ -4735,8 +4734,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
     }
 
     // Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value)
-    if (clear_active_id && g.ActiveId == id)
+    // Otherwise request text input ahead for next frame.
+    if (g.ActiveId == id && clear_active_id)
         ClearActiveID();
+    else if (g.ActiveId == id)
+        g.WantTextInputNextFrame = 1;
 
     // Render frame
     if (!is_multiline)