Canceling text input with [esc] key uses stb_textedit facilities to restore original value. This makes restoration undoable using hotkeys.
Fixes #3008.
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 099f8f0..9a60ef2 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -76,6 +76,7 @@
those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups]
- ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'.
- ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available.
+- InputText: Fix crash when executing undo action after clearing input with ESC (#3008). [@rokups]
- MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border.
- Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog]
- Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index a5aa86b..777530b 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -3828,6 +3828,25 @@
{
apply_new_text = state->InitialTextA.Data;
apply_new_text_length = state->InitialTextA.Size - 1;
+
+ // Select all text
+ state->OnKeyPressed(STB_TEXTEDIT_K_TEXTSTART);
+ state->OnKeyPressed(STB_TEXTEDIT_K_TEXTEND | STB_TEXTEDIT_K_SHIFT);
+
+ // Paste converted text or empty buffer
+ if (state->InitialTextA.size() > 1)
+ {
+ ImVector<ImWchar> w_text;
+ const char* apply_new_text_end = apply_new_text + apply_new_text_length + 1;
+ w_text.resize(ImTextCountCharsFromUtf8(apply_new_text, apply_new_text_end));
+ ImTextStrFromUtf8(w_text.Data, w_text.Size, apply_new_text, apply_new_text_end);
+ ImStb::stb_textedit_paste(state, &state->Stb, w_text.Data, w_text.Size);
+ }
+ else
+ {
+ ImWchar empty = 0;
+ ImStb::stb_textedit_paste(state, &state->Stb, &empty, 0);
+ }
}
}