MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / stb_textedit_discard_redo

Function stb_textedit_discard_redo

KBotExt/imgui/imstb_textedit.h:1135–1163  ·  view source on GitHub ↗

discard the oldest entry in the redo list--it's bad if this ever happens, but because undo & redo have to store the actual characters in different cases, the redo character buffer can fill up even though the undo buffer didn't

Source from the content-addressed store, hash-verified

1133// characters in different cases, the redo character buffer can
1134// fill up even though the undo buffer didn't
1135static void stb_textedit_discard_redo(StbUndoState* state)
1136{
1137 int k = STB_TEXTEDIT_UNDOSTATECOUNT - 1;
1138
1139 if (state->redo_point <= k) {
1140 // if the k'th undo state has characters, clean those up
1141 if (state->undo_rec[k].char_storage >= 0) {
1142 int n = state->undo_rec[k].insert_length, i;
1143 // move the remaining redo character data to the end of the buffer
1144 state->redo_char_point += n;
1145 STB_TEXTEDIT_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point - n, (size_t)((STB_TEXTEDIT_UNDOCHARCOUNT - state->redo_char_point) * sizeof(STB_TEXTEDIT_CHARTYPE)));
1146 // adjust the position of all the other records to account for above memmove
1147 for (i = state->redo_point; i < k; ++i)
1148 if (state->undo_rec[i].char_storage >= 0)
1149 state->undo_rec[i].char_storage += n;
1150 }
1151 // now move all the redo records towards the end of the buffer; the first one is at 'redo_point'
1152 // [DEAR IMGUI]
1153 size_t move_size = (size_t)((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point - 1) * sizeof(state->undo_rec[0]));
1154 const char* buf_begin = (char*)state->undo_rec; (void)buf_begin;
1155 const char* buf_end = (char*)state->undo_rec + sizeof(state->undo_rec); (void)buf_end;
1156 IM_ASSERT(((char*)(state->undo_rec + state->redo_point)) >= buf_begin);
1157 IM_ASSERT(((char*)(state->undo_rec + state->redo_point + 1) + move_size) <= buf_end);
1158 STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point + 1, state->undo_rec + state->redo_point, move_size);
1159
1160 // now move redo_point to point to the new one
1161 ++state->redo_point;
1162 }
1163}
1164
1165static StbUndoRecord* stb_text_create_undo_record(StbUndoState* state, int numchars)
1166{

Callers 1

stb_text_undoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected