mirror of
https://github.com/ocornut/imgui.git
synced 2025-12-20 13:25:39 +00:00
InputText: do not require anymore that CursorPos be clamped by user code. (#9029)
Add clamping outside of callback code + simplify logic. The previous logic checking for difference was because old code e.g. 21d03edcb0 required a ImTextCountCharsFromUtf8() which is not required since #7925.
This commit is contained in:
@@ -5274,11 +5274,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
IM_ASSERT(callback_data.Buf == callback_buf); // Invalid to modify those fields
|
||||
IM_ASSERT(callback_data.BufSize == state->BufCapacity);
|
||||
IM_ASSERT(callback_data.Flags == flags);
|
||||
const bool buf_dirty = callback_data.BufDirty;
|
||||
if (buf_dirty || callback_data.CursorPos != state->Stb->cursor) { state->Stb->cursor = callback_data.CursorPos; state->CursorFollow = true; }
|
||||
if (buf_dirty || callback_data.SelectionStart != state->Stb->select_start) { state->Stb->select_start = (callback_data.SelectionStart == callback_data.CursorPos) ? state->Stb->cursor : callback_data.SelectionStart; }
|
||||
if (buf_dirty || callback_data.SelectionEnd != state->Stb->select_end) { state->Stb->select_end = (callback_data.SelectionEnd == callback_data.SelectionStart) ? state->Stb->select_start : callback_data.SelectionEnd; }
|
||||
if (buf_dirty)
|
||||
if (callback_data.BufDirty || callback_data.CursorPos != state->Stb->cursor)
|
||||
state->CursorFollow = true;
|
||||
state->Stb->cursor = ImClamp(callback_data.CursorPos, 0, callback_data.BufTextLen);
|
||||
state->Stb->select_start = ImClamp(callback_data.SelectionStart, 0, callback_data.BufTextLen);
|
||||
state->Stb->select_end = ImClamp(callback_data.SelectionEnd, 0, callback_data.BufTextLen);
|
||||
if (callback_data.BufDirty)
|
||||
{
|
||||
// Callback may update buffer and thus set buf_dirty even in read-only mode.
|
||||
IM_ASSERT(callback_data.BufTextLen == (int)ImStrlen(callback_data.Buf)); // You need to maintain BufTextLen if you change the text!
|
||||
|
||||
Reference in New Issue
Block a user