mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
InputText: process character input before Return because they may come together (IME batch)
This commit is contained in:
parent
35c0842bcf
commit
2f5c754ef1
37
imgui.cpp
37
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();
|
||||
|
Loading…
Reference in New Issue
Block a user