From 2f5c754ef1485b20b936cec8aa83e0d5b2fedc1a Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 31 Jan 2015 23:51:00 +0000 Subject: [PATCH] InputText: process character input before Return because they may come together (IME batch) --- imgui.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 223c453b4..72918d212 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5132,6 +5132,25 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (edit_state.SelectedAllMouseLock && !io.MouseDown[0]) edit_state.SelectedAllMouseLock = false; + if (g.IO.InputCharacters[0]) + { + // Process text input (before we check for Return because using some IME will effectively send a Return?) + for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++) + { + const ImWchar c = g.IO.InputCharacters[n]; + if (c) + { + // Insert character if they pass filtering + if (InputTextFilterCharacter(c, flags)) + continue; + edit_state.OnKeyPressed(c); + } + } + + // Consume characters + memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); + } + const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0); if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); } else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); } @@ -5193,24 +5212,6 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT } } } - else if (g.IO.InputCharacters[0]) - { - // Text input - for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++) - { - const ImWchar c = g.IO.InputCharacters[n]; - if (c) - { - // Insert character if they pass filtering - if (InputTextFilterCharacter(c, flags)) - continue; - edit_state.OnKeyPressed(c); - } - } - - // Consume characters - memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); - } edit_state.CursorAnim += g.IO.DeltaTime; edit_state.UpdateScrollOffset();