Skip to content

Commit

Permalink
InputText: amends: remove TextAIsValid. (7925)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Sep 5, 2024
1 parent 3ab94ca commit 21dc297
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 0 additions & 1 deletion imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,6 @@ struct IMGUI_API ImGuiInputTextState
int CurLenA; // UTF-8 length of the string in TextA (in bytes)
ImVector<char> TextA; // temporary UTF8 buffer for callbacks and other operations. this is not updated in every code-path! size=capacity.
ImVector<char> InitialTextA; // value to revert to when pressing Escape = backup of end-user buffer at the time of focus (in UTF-8, unaltered)
bool TextAIsValid; // temporary UTF8 buffer is not initially valid before we make the widget active (until then we pull the data from user argument)
int BufCapacityA; // end-user buffer capacity
ImVec2 Scroll; // horizontal offset (managed manually) + vertical scrolling (pulled from child window's own Scroll.y)
ImStb::STB_TexteditState Stb; // state for stb_textedit.h
Expand Down
5 changes: 2 additions & 3 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4447,13 +4447,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
// Preserve cursor position and undo/redo stack if we come back to same widget
// FIXME: Since we reworked this on 2022/06, may want to differentiate recycle_cursor vs recycle_undostate?
bool recycle_state = (state->ID == id && !init_changed_specs && !init_reload_from_user_buf);
if (recycle_state && (state->CurLenA != buf_len || (state->TextAIsValid && strncmp(state->TextA.Data, buf, buf_len) != 0)))
if (recycle_state && (state->CurLenA != buf_len || (strncmp(state->TextA.Data, buf, buf_len) != 0)))
recycle_state = false;

// Start edition
state->ID = id;
state->TextA.resize(buf_size + 1); // we use +1 to make sure that .Data is always pointing to at least an empty string.
state->TextAIsValid = true;
state->CurLenA = (int)strlen(buf);
memcpy(state->TextA.Data, buf, state->CurLenA + 1);

Expand Down Expand Up @@ -4538,7 +4537,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
bool validated = false;

// Select the buffer to render.
const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state && state->TextAIsValid;
const bool buf_display_from_state = (render_cursor || render_selection || g.ActiveId == id) && !is_readonly && state;
const bool is_displaying_hint = (hint != NULL && (buf_display_from_state ? state->TextA.Data : buf)[0] == 0);

// Password pushes a temporary font with only a fallback glyph
Expand Down

0 comments on commit 21dc297

Please sign in to comment.