MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / InputTextReconcileUndoState

Function InputTextReconcileUndoState

external/imgui/imgui_widgets.cpp:4555–4577  ·  view source on GitHub ↗

Find the shortest single replacement we can make to get from old_buf to new_buf Note that this doesn't directly alter state->TextA, state->TextLen. They are expected to be made valid separately. FIXME: Ideally we should transition toward (1) making InsertChars()/DeleteChars() update undo-stack (2) discourage (and keep reconcile) or obsolete (and remove reconcile) accessing buffer directly.

Source from the content-addressed store, hash-verified

4553// Note that this doesn't directly alter state->TextA, state->TextLen. They are expected to be made valid separately.
4554// FIXME: Ideally we should transition toward (1) making InsertChars()/DeleteChars() update undo-stack (2) discourage (and keep reconcile) or obsolete (and remove reconcile) accessing buffer directly.
4555static void InputTextReconcileUndoState(ImGuiInputTextState* state, const char* old_buf, int old_length, const char* new_buf, int new_length)
4556{
4557 const int shorter_length = ImMin(old_length, new_length);
4558 int first_diff;
4559 for (first_diff = 0; first_diff < shorter_length; first_diff++)
4560 if (old_buf[first_diff] != new_buf[first_diff])
4561 break;
4562 if (first_diff == old_length && first_diff == new_length)
4563 return;
4564
4565 int old_last_diff = old_length - 1;
4566 int new_last_diff = new_length - 1;
4567 for (; old_last_diff >= first_diff && new_last_diff >= first_diff; old_last_diff--, new_last_diff--)
4568 if (old_buf[old_last_diff] != new_buf[new_last_diff])
4569 break;
4570
4571 const int insert_len = new_last_diff - first_diff + 1;
4572 const int delete_len = old_last_diff - first_diff + 1;
4573 if (insert_len > 0 || delete_len > 0)
4574 if (IMSTB_TEXTEDIT_CHARTYPE* p = stb_text_createundo(&state->Stb->undostate, first_diff, delete_len, insert_len))
4575 for (int i = 0; i < delete_len; i++)
4576 p[i] = old_buf[first_diff + i];
4577}
4578
4579// As InputText() retain textual data and we currently provide a path for user to not retain it (via local variables)
4580// we need some form of hook to reapply data back to user buffer on deactivation frame. (#4714)

Callers 1

InputTextExMethod · 0.85

Calls 2

ImMinFunction · 0.85
stb_text_createundoFunction · 0.85

Tested by

no test coverage detected