| 1277 | } |
| 1278 | |
| 1279 | static void stb_text_redo(STB_TEXTEDIT_STRING* str, STB_TexteditState* state) |
| 1280 | { |
| 1281 | StbUndoState* s = &state->undostate; |
| 1282 | StbUndoRecord* u, r; |
| 1283 | if (s->redo_point == STB_TEXTEDIT_UNDOSTATECOUNT) |
| 1284 | return; |
| 1285 | |
| 1286 | // we need to do two things: apply the redo record, and create an undo record |
| 1287 | u = &s->undo_rec[s->undo_point]; |
| 1288 | r = s->undo_rec[s->redo_point]; |
| 1289 | |
| 1290 | // we KNOW there must be room for the undo record, because the redo record |
| 1291 | // was derived from an undo record |
| 1292 | |
| 1293 | u->delete_length = r.insert_length; |
| 1294 | u->insert_length = r.delete_length; |
| 1295 | u->where = r.where; |
| 1296 | u->char_storage = -1; |
| 1297 | |
| 1298 | if (r.delete_length) { |
| 1299 | // the redo record requires us to delete characters, so the undo record |
| 1300 | // needs to store the characters |
| 1301 | |
| 1302 | if (s->undo_char_point + u->insert_length > s->redo_char_point) { |
| 1303 | u->insert_length = 0; |
| 1304 | u->delete_length = 0; |
| 1305 | } |
| 1306 | else { |
| 1307 | int i; |
| 1308 | u->char_storage = s->undo_char_point; |
| 1309 | s->undo_char_point = s->undo_char_point + u->insert_length; |
| 1310 | |
| 1311 | // now save the characters |
| 1312 | for (i = 0; i < u->insert_length; ++i) |
| 1313 | s->undo_char[u->char_storage + i] = STB_TEXTEDIT_GETCHAR(str, u->where + i); |
| 1314 | } |
| 1315 | |
| 1316 | STB_TEXTEDIT_DELETECHARS(str, r.where, r.delete_length); |
| 1317 | } |
| 1318 | |
| 1319 | if (r.insert_length) { |
| 1320 | // easy case: need to insert n characters |
| 1321 | STB_TEXTEDIT_INSERTCHARS(str, r.where, &s->undo_char[r.char_storage], r.insert_length); |
| 1322 | s->redo_char_point += r.insert_length; |
| 1323 | } |
| 1324 | |
| 1325 | state->cursor = r.where + r.insert_length; |
| 1326 | |
| 1327 | s->undo_point++; |
| 1328 | s->redo_point++; |
| 1329 | } |
| 1330 | |
| 1331 | static void stb_text_makeundo_insert(STB_TexteditState* state, int where, int length) |
| 1332 | { |
no test coverage detected