|
|
@@ -37,7 +37,7 @@ Index of this file:
|
|
|
#endif
|
|
|
#include "imgui_internal.h"
|
|
|
|
|
|
-#include <ctype.h> // toupper, isprint
|
|
|
+#include <ctype.h> // toupper
|
|
|
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
|
|
|
#include <stddef.h> // intptr_t
|
|
|
#else
|
|
|
@@ -3154,7 +3154,8 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
|
|
{
|
|
|
unsigned int c = *p_char;
|
|
|
|
|
|
- if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
|
|
|
+ // Filter non-printable (NB: isprint is unreliable! see #2467)
|
|
|
+ if (c < 0x20)
|
|
|
{
|
|
|
bool pass = false;
|
|
|
pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline));
|
|
|
@@ -3163,9 +3164,11 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
|
|
|
+ // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
|
|
|
+ if (c >= 0xE000 && c <= 0xF8FF)
|
|
|
return false;
|
|
|
|
|
|
+ // Generic named filters
|
|
|
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific))
|
|
|
{
|
|
|
if (flags & ImGuiInputTextFlags_CharsDecimal)
|
|
|
@@ -3189,6 +3192,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ // Custom callback filter
|
|
|
if (flags & ImGuiInputTextFlags_CallbackCharFilter)
|
|
|
{
|
|
|
ImGuiInputTextCallbackData callback_data;
|
|
|
@@ -3344,7 +3348,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|
|
FocusWindow(window);
|
|
|
IM_ASSERT(ImGuiNavInput_COUNT < 32);
|
|
|
g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel);
|
|
|
- if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out
|
|
|
+ if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out as we will use the \t character.
|
|
|
g.ActiveIdBlockNavInputFlags |= (1 << ImGuiNavInput_KeyTab_);
|
|
|
if (!is_multiline && !(flags & ImGuiInputTextFlags_CallbackHistory))
|
|
|
g.ActiveIdAllowNavDirFlags = ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down));
|
|
|
@@ -3446,16 +3450,28 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|
|
if (state->SelectedAllMouseLock && !io.MouseDown[0])
|
|
|
state->SelectedAllMouseLock = false;
|
|
|
|
|
|
+ // It is ill-defined whether the back-end needs to send a \t character when pressing the TAB keys.
|
|
|
+ // Win32 and GLFW naturally do it but not SDL.
|
|
|
+ const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper);
|
|
|
+ if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly)
|
|
|
+ if (!io.InputQueueCharacters.contains('\t'))
|
|
|
+ {
|
|
|
+ unsigned int c = '\t'; // Insert TAB
|
|
|
+ if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
|
|
+ state->OnKeyPressed((int)c);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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.
|
|
|
if (io.InputQueueCharacters.Size > 0)
|
|
|
{
|
|
|
- // Process 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.
|
|
|
- bool ignore_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper);
|
|
|
- if (!ignore_inputs && !is_readonly && !user_nav_input_start)
|
|
|
+ if (!ignore_char_inputs && !is_readonly && !user_nav_input_start)
|
|
|
for (int n = 0; n < io.InputQueueCharacters.Size; n++)
|
|
|
{
|
|
|
// Insert character if they pass filtering
|
|
|
unsigned int c = (unsigned int)io.InputQueueCharacters[n];
|
|
|
+ if (c == '\t' && io.KeyShift)
|
|
|
+ continue;
|
|
|
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
|
|
state->OnKeyPressed((int)c);
|
|
|
}
|
|
|
@@ -3517,12 +3533,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|
|
state->OnKeyPressed((int)c);
|
|
|
}
|
|
|
}
|
|
|
- else if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !io.KeyCtrl && !io.KeyShift && !io.KeyAlt && !is_readonly)
|
|
|
- {
|
|
|
- unsigned int c = '\t'; // Insert TAB
|
|
|
- if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
|
|
- state->OnKeyPressed((int)c);
|
|
|
- }
|
|
|
else if (IsKeyPressedMap(ImGuiKey_Escape))
|
|
|
{
|
|
|
clear_active_id = cancel_edit = true;
|