MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / InputTextReconcileUndoState

Function InputTextReconcileUndoState

3rdparty/imgui/src/imgui_widgets.cpp:4553–4575  ·  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

4551// Note that this doesn't directly alter state->TextA, state->TextLen. They are expected to be made valid separately.
4552// 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.
4553static void InputTextReconcileUndoState(ImGuiInputTextState* state, const char* old_buf, int old_length, const char* new_buf, int new_length)
4554{
4555 const int shorter_length = ImMin(old_length, new_length);
4556 int first_diff;
4557 for (first_diff = 0; first_diff < shorter_length; first_diff++)
4558 if (old_buf[first_diff] != new_buf[first_diff])
4559 break;
4560 if (first_diff == old_length && first_diff == new_length)
4561 return;
4562
4563 int old_last_diff = old_length - 1;
4564 int new_last_diff = new_length - 1;
4565 for (; old_last_diff >= first_diff && new_last_diff >= first_diff; old_last_diff--, new_last_diff--)
4566 if (old_buf[old_last_diff] != new_buf[new_last_diff])
4567 break;
4568
4569 const int insert_len = new_last_diff - first_diff + 1;
4570 const int delete_len = old_last_diff - first_diff + 1;
4571 if (insert_len > 0 || delete_len > 0)
4572 if (IMSTB_TEXTEDIT_CHARTYPE* p = stb_text_createundo(&state->Stb->undostate, first_diff, delete_len, insert_len))
4573 for (int i = 0; i < delete_len; i++)
4574 p[i] = old_buf[first_diff + i];
4575}
4576
4577// As InputText() retain textual data and we currently provide a path for user to not retain it (via local variables)
4578// 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