Skip to content

Commit 00f12b9

Browse files
committed
InputText: Fixed not calling CallbackEdit on revert/clear with Escape key. (ocornut#8273) + rework comments.
Seems like there is no reason to not run that path. Amend ancient 9501cd9, f3ab5e6
1 parent a604d4f commit 00f12b9

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Other changes:
6262
value is being modified. (#8242)
6363
- InputText: Added sanity check to detect some cases of passing a non
6464
zero-terminated input buffer.
65+
- InputText: Fixed not calling CallbackEdit on revert/clear with Escape key,
66+
although IsItemEdited() was behaving correctly. (#8273)
6567
- Tables: Fixed TableAngledHeadersRow() creating an infinite horizontal
6668
scrolling region when the table is hosted in a viewport with negative
6769
coordinates.

imgui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ enum ImGuiInputTextFlags_
11821182
ImGuiInputTextFlags_CallbackAlways = 1 << 20, // Callback on each iteration. User code may query cursor position, modify text buffer.
11831183
ImGuiInputTextFlags_CallbackCharFilter = 1 << 21, // Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
11841184
ImGuiInputTextFlags_CallbackResize = 1 << 22, // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
1185-
ImGuiInputTextFlags_CallbackEdit = 1 << 23, // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)
1185+
ImGuiInputTextFlags_CallbackEdit = 1 << 23, // Callback on any edit. Note that InputText() already returns true on edit + you can always use IsItemEdited(). The callback is useful to manipulate the underlying buffer while focus is active.
11861186

11871187
// Obsolete names
11881188
//ImGuiInputTextFlags_AlwaysInsertMode = ImGuiInputTextFlags_AlwaysOverwrite // [renamed in 1.82] name was not matching behavior
@@ -2442,7 +2442,7 @@ struct ImGuiIO
24422442
// Shared state of InputText(), passed as an argument to your callback when a ImGuiInputTextFlags_Callback* flag is used.
24432443
// The callback function should return 0 by default.
24442444
// Callbacks (follow a flag name and see comments in ImGuiInputTextFlags_ declarations for more details)
2445-
// - ImGuiInputTextFlags_CallbackEdit: Callback on buffer edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)
2445+
// - ImGuiInputTextFlags_CallbackEdit: Callback on buffer edit. Note that InputText() already returns true on edit + you can always use IsItemEdited(). The callback is useful to manipulate the underlying buffer while focus is active.
24462446
// - ImGuiInputTextFlags_CallbackAlways: Callback on each iteration
24472447
// - ImGuiInputTextFlags_CallbackCompletion: Callback on pressing TAB
24482448
// - ImGuiInputTextFlags_CallbackHistory: Callback on pressing Up/Down arrows

imgui_widgets.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4977,19 +4977,17 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
49774977
}
49784978
}
49794979

4980-
// When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer
4981-
// before clearing ActiveId, even though strictly speaking it wasn't modified on this frame.
4982-
// If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail.
4983-
// This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage
4980+
// FIXME-OPT: We always reapply the live buffer back to the input buffer before clearing ActiveId,
4981+
// even though strictly speaking it wasn't modified on this frame. Should mark dirty state from the stb_textedit callbacks.
4982+
// If we do that, need to ensure that as special case, 'validated == true' also writes back.
4983+
// This also allows the user to use InputText() without maintaining any user-side storage.
49844984
// (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object
49854985
// unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize).
4986-
const bool apply_edit_back_to_user_buffer = !revert_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
4986+
const bool apply_edit_back_to_user_buffer = true;// !revert_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
49874987
if (apply_edit_back_to_user_buffer)
49884988
{
4989-
// Apply new value immediately - copy modified buffer back
4989+
// Apply current edited text immediately.
49904990
// Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer
4991-
// FIXME: We actually always render 'buf' when calling DrawList->AddText, making the comment above incorrect.
4992-
// FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks.
49934991

49944992
// User callback
49954993
if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackAlways)) != 0)

0 commit comments

Comments
 (0)