mirror of https://github.com/ocornut/imgui
InputText: Do not filter private unicode codepoints (e.g. icons) when pasted from clipboard. (#4005)
This commit is contained in:
parent
feb8b1e32d
commit
f08566b4d7
|
@ -49,6 +49,7 @@ Other Changes:
|
||||||
consistent with the compile-time default. (#3922)
|
consistent with the compile-time default. (#3922)
|
||||||
- DragScalar: Add default value for v_speed argument to match higher-level functions. (#3922) [@eliasdaler]
|
- DragScalar: Add default value for v_speed argument to match higher-level functions. (#3922) [@eliasdaler]
|
||||||
- ColorEdit4: Alpha default to 255 (instead of 0) when omitted in hex input. (#3973) [@squadack]
|
- ColorEdit4: Alpha default to 255 (instead of 0) when omitted in hex input. (#3973) [@squadack]
|
||||||
|
- InputText: Do not filter private unicode codepoints (e.g. icons) when pasted from clipboard. (#4005) [@dougbinks]
|
||||||
- Popups: Added 'OpenPopup(ImGuiID id)' overload to facilitate calling from nested stacks. (#3993, #331) [@zlash]
|
- Popups: Added 'OpenPopup(ImGuiID id)' overload to facilitate calling from nested stacks. (#3993, #331) [@zlash]
|
||||||
- Backends: SDL: Rework global mouse pos availability check listing supported platforms explicitly,
|
- Backends: SDL: Rework global mouse pos availability check listing supported platforms explicitly,
|
||||||
effectively fixing mouse access on Raspberry Pi. (#2837, #3950) [@lethal-guitar, @hinxx]
|
effectively fixing mouse access on Raspberry Pi. (#2837, #3950) [@lethal-guitar, @hinxx]
|
||||||
|
|
|
@ -827,6 +827,7 @@ enum ImGuiInputSource
|
||||||
ImGuiInputSource_Keyboard,
|
ImGuiInputSource_Keyboard,
|
||||||
ImGuiInputSource_Gamepad,
|
ImGuiInputSource_Gamepad,
|
||||||
ImGuiInputSource_Nav, // Stored in g.ActiveIdSource only
|
ImGuiInputSource_Nav, // Stored in g.ActiveIdSource only
|
||||||
|
ImGuiInputSource_Clipboard, // Currently only used by InputText()
|
||||||
ImGuiInputSource_COUNT
|
ImGuiInputSource_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1);
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
// For InputTextEx()
|
// For InputTextEx()
|
||||||
static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data);
|
static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source);
|
||||||
static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end);
|
static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end);
|
||||||
static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false);
|
static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false);
|
||||||
|
|
||||||
|
@ -3764,8 +3764,9 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return false to discard a character.
|
// Return false to discard a character.
|
||||||
static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data, ImGuiInputSource input_source)
|
||||||
{
|
{
|
||||||
|
IM_ASSERT(input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Clipboard);
|
||||||
unsigned int c = *p_char;
|
unsigned int c = *p_char;
|
||||||
|
|
||||||
// Filter non-printable (NB: isprint is unreliable! see #2467)
|
// Filter non-printable (NB: isprint is unreliable! see #2467)
|
||||||
|
@ -3778,15 +3779,18 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
|
if (input_source != ImGuiInputSource_Clipboard)
|
||||||
if (c == 127)
|
{
|
||||||
return false;
|
// We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817)
|
||||||
|
if (c == 127)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
|
// Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
|
||||||
if (c >= 0xE000 && c <= 0xF8FF)
|
if (c >= 0xE000 && c <= 0xF8FF)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Filter Unicode ranges we are not handling in this build.
|
// Filter Unicode ranges we are not handling in this build
|
||||||
if (c > IM_UNICODE_CODEPOINT_MAX)
|
if (c > IM_UNICODE_CODEPOINT_MAX)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -4111,7 +4115,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||||
if (!io.InputQueueCharacters.contains('\t'))
|
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))
|
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard))
|
||||||
state->OnKeyPressed((int)c);
|
state->OnKeyPressed((int)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4126,7 +4130,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||||
unsigned int c = (unsigned int)io.InputQueueCharacters[n];
|
unsigned int c = (unsigned int)io.InputQueueCharacters[n];
|
||||||
if (c == '\t' && io.KeyShift)
|
if (c == '\t' && io.KeyShift)
|
||||||
continue;
|
continue;
|
||||||
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard))
|
||||||
state->OnKeyPressed((int)c);
|
state->OnKeyPressed((int)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4190,7 +4194,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||||
else if (!is_readonly)
|
else if (!is_readonly)
|
||||||
{
|
{
|
||||||
unsigned int c = '\n'; // Insert new line
|
unsigned int c = '\n'; // Insert new line
|
||||||
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard))
|
||||||
state->OnKeyPressed((int)c);
|
state->OnKeyPressed((int)c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4243,7 +4247,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||||
s += ImTextCharFromUtf8(&c, s, NULL);
|
s += ImTextCharFromUtf8(&c, s, NULL);
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data))
|
if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Clipboard))
|
||||||
continue;
|
continue;
|
||||||
clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
|
clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue