Skip to content

Commit 83efdce

Browse files
rokupsocornut
authored andcommitted
Canceling text input with [esc] key uses stb_textedit facilities to restore original value. This makes restoration undoable using hotkeys.
Fixes #3008.
1 parent 5a437f1 commit 83efdce

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Other Changes:
7676
those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups]
7777
- ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'.
7878
- ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available.
79+
- InputText: Fix crash when executing undo action after clearing input with ESC (#3008). [@rokups]
7980
- MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border.
8081
- Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog]
8182
- Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we

imgui_widgets.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,25 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
38283828
{
38293829
apply_new_text = state->InitialTextA.Data;
38303830
apply_new_text_length = state->InitialTextA.Size - 1;
3831+
3832+
// Select all text
3833+
state->OnKeyPressed(STB_TEXTEDIT_K_TEXTSTART);
3834+
state->OnKeyPressed(STB_TEXTEDIT_K_TEXTEND | STB_TEXTEDIT_K_SHIFT);
3835+
3836+
// Paste converted text or empty buffer
3837+
if (state->InitialTextA.size() > 1)
3838+
{
3839+
ImVector<ImWchar> w_text;
3840+
const char* apply_new_text_end = apply_new_text + apply_new_text_length + 1;
3841+
w_text.resize(ImTextCountCharsFromUtf8(apply_new_text, apply_new_text_end));
3842+
ImTextStrFromUtf8(w_text.Data, w_text.Size, apply_new_text, apply_new_text_end);
3843+
ImStb::stb_textedit_paste(state, &state->Stb, w_text.Data, w_text.Size);
3844+
}
3845+
else
3846+
{
3847+
ImWchar empty = 0;
3848+
ImStb::stb_textedit_paste(state, &state->Stb, &empty, 0);
3849+
}
38313850
}
38323851
}
38333852

0 commit comments

Comments
 (0)