InputText: Fixed pressing Tab emitting two tabs characters. (#2467, #1336)

Using Tab keys entirely now, ignoring Tab character. Technically affect who owns the repeat rate.
This commit is contained in:
ocornut 2022-03-24 12:04:49 +01:00
parent 16ddc1698d
commit dfbe938e54
2 changed files with 11 additions and 10 deletions

View File

@ -55,6 +55,8 @@ Other Changes:
clipper instance. High-level languages (Lua,Rust etc.) would typically be affected. (#4822) clipper instance. High-level languages (Lua,Rust etc.) would typically be affected. (#4822)
- IsItemHovered(): added ImGuiHoveredFlags_NoNavOverride to disable the behavior where the - IsItemHovered(): added ImGuiHoveredFlags_NoNavOverride to disable the behavior where the
return value is overriden by focus when gamepad/keyboard navigation is active. return value is overriden by focus when gamepad/keyboard navigation is active.
- InputText: Fixed pressing Tab emitting two tabs characters because of dual Keys/Chars events being
trickled with the new input queue (happened on some backends only). (#2467, #1336)
- Tables: Fixed incorrect border height used for logic when resizing one of several synchronized - Tables: Fixed incorrect border height used for logic when resizing one of several synchronized
instance of a same table ID, when instances have a different height. (#3955). instance of a same table ID, when instances have a different height. (#3955).
- Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate.

View File

@ -3815,7 +3815,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
if (c < 0x20) if (c < 0x20)
{ {
bool pass = false; bool pass = false;
pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); // Note that an Enter KEY will emit \r and be ignored (we poll for KEY in InputText() code)
pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput));
if (!pass) if (!pass)
return false; return false;
@ -4201,16 +4201,15 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
if (state->SelectedAllMouseLock && !io.MouseDown[0]) if (state->SelectedAllMouseLock && !io.MouseDown[0])
state->SelectedAllMouseLock = false; state->SelectedAllMouseLock = false;
// It is ill-defined whether the backend needs to send a \t character when pressing the TAB keys. // We except backends to emit a Tab key but some also emit a Tab character which we ignore (#2467, #1336)
// Win32 and GLFW naturally do it but not SDL. // (For Tab and Enter: Win32/SFML/Allegro are sending both keys and chars, GLFW and SDL are only sending keys. For Space they all send all threes)
const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper);
if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressed(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly) if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressed(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly)
if (!io.InputQueueCharacters.contains('\t')) {
{ unsigned int c = '\t'; // Insert TAB
unsigned int c = '\t'; // Insert TAB if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard))
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) state->OnKeyPressed((int)c);
state->OnKeyPressed((int)c); }
}
// Process regular text input (before we check for Return because using some IME will effectively send a Return?) // Process regular text input (before we check for Return because using some IME will effectively send a Return?)
// We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters. // We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters.
@ -4221,7 +4220,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
{ {
// Insert character if they pass filtering // Insert character if they pass filtering
unsigned int c = (unsigned int)io.InputQueueCharacters[n]; unsigned int c = (unsigned int)io.InputQueueCharacters[n];
if (c == '\t' && io.KeyShift) if (c == '\t') // Skip Tab, see above.
continue; continue;
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard))
state->OnKeyPressed((int)c); state->OnKeyPressed((int)c);